Android JSONObject的大尺寸JSON字符串不起作用
Android JSONObject的大尺寸JSON字符串不起作用,android,json,jsonobject,Android,Json,Jsonobject,以上代码运行良好。但是这个JSON()URL字符串没有转换成JSON对象。我认为这是一个大字符串,还添加了错误屏幕截图。您的测试数据包含在基于[]的数组中。您需要将其解析为json数组,而不是json对象 protected class saveBtnClickHandler implements OnClickListener{ @Override public void onClick(View v) { String jsonRest = loadJs
以上代码运行良好。但是这个JSON()URL字符串没有转换成JSON对象。我认为这是一个大字符串,还添加了错误屏幕截图。您的测试数据包含在基于[]的数组中。您需要将其解析为json数组,而不是json对象
protected class saveBtnClickHandler implements OnClickListener{
@Override
public void onClick(View v) {
String jsonRest = loadJsonDataFromURL("http://thirddhaba.appspot.com/api/v1/circle/condensed/data/?circle_id=1");
try {
JSONObject jsonObj = new JSONObject(jsonRest);
} catch (JSONException e) {
android.util.Log.e("JSON Parser", "Error parsing data " + e.toString());
}
}
}
protected String loadJsonDataFromURL(String url){
String jsonStr = null;
try {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(new HttpGet(url));
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
out.close();
jsonStr = out.toString();
} else{
//Closes the connection.
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
} catch (Exception e) {
// TODO: handle exception
}
return jsonStr;
}
替换
JSONArray jsonArr = new JSONArray(jsonRest);
与
我在
在JSONLint中,我注意到它是JSONArray
编辑:供参考
[]用于JSONArray
{}用于JSONObject 你能提供更多的信息吗?LogCar的输出将非常有用。@现在我附加了屏幕截图,请查看问题是字符串的大小,您应该考虑使用流解析JSON,例如,使用我忘记看到这一点,谢谢上司。
JSONObject jsonObj = new JSONObject(jsonRest);
JSONArray jsonArray = new JSONArray(jsonRest);