【问题标题】:org.json.JSONException: End of input at character 0 of Androidorg.json.JSONException:Android 字符 0 处的输入结束
【发布时间】:2016-09-06 05:12:57
【问题描述】:

我正在尝试从 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

【问题讨论】:

  • 响应服务方式是get还是post方式?检查你的服务。
  • 打印你的responseString并检查它是否是有效的json
  • 我打印了 responseString 但它是空白的

标签: android json web-services


【解决方案1】:

您可能收到空白回复。它不为空,但响应为空。所以你得到了这个错误,而不是 Nullpointer 异常。

与您的后端开发人员核实

【讨论】:

  • 后端(CMS)端的问题
【解决方案2】:

responseString 为空白,因此您不能: 成功 = json.getString("iserror"); 检查您的 httpPost 和服务

【讨论】:

    猜你喜欢
    • 2014-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 2015-11-13
    • 1970-01-01
    相关资源
    最近更新 更多