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;
}
上面的代码工作正常。但是这个JSON(Link)URL字符串没有转换成JSON对象。我认为这是大字符串还添加错误屏幕截图。大尺寸JSON字符串到JSONObject不起作用
您能否提供更多信息? logcat的输出将非常有用。 – AitorTheRed
@AitorTheRed现在我附上截图请检查 – Rajkamal
如果问题是字符串的大小,你应该考虑使用流解析JSON,例如。使用http://jackson.codehaus.org/ –