我想解析我的应用程序中的JSON。Logcat上的JSON错误。不能找到从Logcat错误是什么
我的JSONParser.java如下。
public class JSONParser {
static InputStream is = null;
static JSONObject jObj = null;
static String json = "";
public JSONObject getJSONFromUrl(String url, List<NameValuePair> params) {
// Making HTTP request
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
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();
json = sb.toString();
Log.e("JSON", json);
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
// return JSON String
return jObj;
}
}
我的JSON从这里 http://ketozen.com/ketorecipes/
这里发送到该设备是引擎收录输出 http://pastebin.com/s1M8HzNr
这是在我的日志。 http://pastebin.com/QTUphjeR
难道有人请澄清问题出在哪里?
是getJSONFromUrl在UI线程上运行? – Blackbelt
你的logcat没问题。但是你应该删除'Log.e(“JSON”,json);'。为什么在成功结果之后记录错误? – vorrtex
printStackTrace而不是日志e.toString。 – njzk2