我试图从服务器获得答案并将其转换为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":"Not Found"},"content":"用户认证失败"}
但是在代码字符串上JSONObject jObject = new JSONObject(result);
- 它转到 return null
; =(( 我试图创建JSONArray
,但它返回给我一个扩展,我可以JSONARRAY
从JSONObject
.