0
저는 안드로이드 플랫폼에 익숙하지 않습니다. 전에 많은 json 페이지를 파싱했지만, 하나의 링크가 문제를 일으키고 있습니다. 다음 함수를 사용하여 json 객체를 반환합니다. 프로그램은 reader.readline()에서 멈추고 로딩은 멈추지 않습니다.android json 파싱이 로딩을 계속합니다.
public JSONObject getJSONFromUrl(String url) {
DefaultHttpClient httpClient = new DefaultHttpClient();
try {
HttpResponse httpResponse = httpClient.execute(new HttpGet(url));
if (httpResponse.getStatusLine().getStatusCode()==200)
{
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
System.out.println("Unsupported Encoding");
} catch (ClientProtocolException e) {
e.printStackTrace();
System.out.println("Client Protocol");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IO");
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
is.close();
jsonStr = sb.toString();
} catch (Exception e) {
System.out.println("Error here");
Log.e("Buffer Error", "Error converting result " + e.toString());
}
// try parse the string to a JSON object
try {
jObj = new JSONObject(jsonStr);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
return jObj;
}
아무 것도 제안 할 수 있습니까?
나는 엔티티도 시도했다. URL은 브라우저에서 정상적으로 작동하지만 거기에 문제가있는 것 같아요. 올바르게 작동하지만 문자열에서 json을 저장할 때 발생합니다.하지만 링크에서 가져 오지는 마십시오. –