【发布时间】: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