JSON 배열을 다운로드 할 때 문자열의 1/4을 잘라내는데 꽤 큰 것입니다.하지만 전체 문자열을 가져와야합니다.JSON 응답이 부분적으로 끊어집니다.
LogCat에 오류가 없습니다. 이것은 내가 사용하고있는 방법이며, 몇 번이고 그것을 끝내고 커팅을하지 못하는 이유를 볼 수 없습니다. 나는 이것에 아주 새롭다 그러나.
public static JSONArray getJSONfromURL(String url){
//initialize
InputStream is = null;
String result = "";
JSONArray jArray = null;
//http post
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch (Exception e) {
Log.e("log_tag", "Error in http connection "+e.toString());
}
//convert response to string
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 + "\n");
}
is.close();
result=sb.toString();
} catch (Exception e) {
Log.e("log_tag", "Error converting result "+e.toString());
}
//try parse the string to a JSON object
try {
Log.d("log_tag", "jresult: " + result + "finish");
jArray = new JSONArray(result);
//Log.e("log_tag", "result: " + jArray.toString());
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data "+e.toString());
}
return jArray;
}
일단 이것이 금이 간다면 나는 설정 될 것입니다. 나는 이것을 미래의 프로젝트에도 사용할 수업으로 만들 것이다. 그래서 나는 그것을 계속 재건하지 않아도된다!
편집 : 마커가지도에 추가해야 For 루프 :
try{
for(int i=0;i<arrayResultFromURL.length();i++){
JSONObject json_data = arrayResultFromURL.getJSONObject(i);
// assign attributes from the JSON string to local variables
String id =json_data.getString("id");
String title =json_data.getString("title");
String strap =json_data.getString("strap");
Double lat = (double) json_data.getDouble("lat");
Double lon = (double) json_data.getDouble("long");
theMap.addMarker(new MarkerOptions()
.position(new LatLng(lat, lon))
.title(title)
.snippet(strap));
}
}catch (Exception e){
Log.e("log_tag", "error in array: " + e.toString());
}
결과가 돌아오고 예상되는 결과는 무엇입니까? – Raghunandan
이 코드는 http://pastebin.com/KLr2Czsb를 모두 반환하고 http://pastebin.com/bgSqbNxi –
을 통해 1/4 정도 잘라냅니다. 코드에 어떤 문제가 있는지 알 수 없습니다. 결과 로깅을 시도하고 – Raghunandan