【发布时间】:2012-06-12 11:46:37
【问题描述】:
我试图从服务器获取答案并将其转换为JSONObject。
现在我有这个代码
private JSONObject sendData(ArrayList<NameValuePair> data, String actionname)
{
// 1) Connect via HTTP. 2) Encode data. 3) Send data.
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new
HttpPost(actionname);
httppost.setEntity(new UrlEncodedFormEntity(data));
HttpResponse response = httpclient.execute(httppost);
// Log.i("postData", response.getStatusLine().toString());
InputStream is = response.getEntity().getContent();
String result = convertStreamToString(is);
// JSONArray jArr = new JSONArray (result);
// int eventID = jArr.getJSONObject(0).getInt("eventID");
JSONObject jObject = new JSONObject(result);
return jObject;
}
catch(Exception e)
{
Log.e("log_tag", "Error: "+e.toString());
}
return null;
}
在result 字符串变量中我有这个
{"status":{"code":404,"text":"未找到"},"content":"用户 身份验证失败”}
但是在代码字符串JSONObject jObject = new JSONObject(result); - 它转到返回null; =((我试图创建JSONArray,但它返回给我一个扩展,我可以从JSONObject创建JSONARRAY。
【问题讨论】:
-
你必须在 JSONObject jObject = new JSONObject(result); jsut在日志中打印结果并检查............
标签: java android json web-services