我正在将数据发送到服务器,并尝试解析格式为 json 的响应{"count":"2"}
,但我遇到了异常
这是我的代码
post(serverUrl, params);
HttpClient httpClient = new DefaultHttpClient();
try{
get = new HttpPost(url);
r = httpClient.execute(get);
he = r.getEntity();
InputStream is = he.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) { sb.append(line + "\n"); }
String result = sb.toString();
jObj = new JSONObject(result);
Log.d(TAG, "Count is" + jObj);
count = jObj.getString("count");
Log.d(TAG, "Count is" + count);
}
catch (Exception e) { e.printStackTrace(); }