org.json.JSONException:Android的字符0输入结束

时间:2016-09-06 05:12:58

标签: android json web-services

我正在尝试从JSON中检索值,并且我将responseString视为空。这是我的代码

HttpClient httpClient = new DefaultHttpClient();
HttpContext httpContext = new BasicHttpContext();
HttpPost httpPost = new HttpPost(URL);
String jsons = "";
JSONObject jsonObject = new JSONObject();
jsonObject.put("tbl_id", tableid);
jsonObject.put("imei_no", phneimeino);
jsonObject.put("server_id", usrid);
jsonObject.put("customers", customerName1 + "," + customerName2 + "," + customerName3);
Log.w("JSON OBJECT is ", jsonObject.toString());
jsons = jsonObject.toString();
StringEntity se = new StringEntity(jsons);
httpPost.setEntity(se);
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
HttpResponse response = httpClient.execute(httpPost, httpContext);
HttpEntity entity = response.getEntity();
String responseString = EntityUtils.toString(entity);
Log.i("Response", responseString);
JSONObject json = new JSONObject(responseString);
success = json.getString("iserror");

这里responseString为空,并将异常显示为

org.json.JSONException: End of input at character 0 of

2 个答案:

答案 0 :(得分:1)

你可能会得到一个空白的回复。它不是null但响应是空的。所以你得到这个错误而不是Nullpointer异常。

与您的后端开发人员联系

答案 1 :(得分:1)

responseString为空,所以你不能:       success = json.getString(“iserror”); 检查你的httpPost和服务