我想知道如何将来自服务器的 http 响应转换为适当的可解析 JSON 数组
try {
HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(
"http://riffre.com/chatapp/search.php?format=json");
postRequest.setEntity(new UrlEncodedFormEntity(nameValuePair));
ResponseHandler<String> responseHandler = new BasicResponseHandler();
responsesrch = httpClient.execute(postRequest, responseHandler);
Log.v("search response", responsesrch);
这是我的代码,我将一些参数以名称值对的形式发布到服务器responseserch
,我得到的值是
{"users":[{"user":{"city":"gurgaon","username":"zxc","userid":"6","gender":"Male","images":"0"}},{"user":{"city":"gurgaon","username":"tarun","userid":"5","gender":"Male","images":"0"}},{"user":{"city":"gurgaon","username":"vips","userid":"4","gender":"Male","images":"0"}},{"user":{"city":"gurgaon","username":"rah","userid":"3","gender":"Male","images":"0"}},{"user":{"city":"gurgaon","username":"aak","userid":"2","gender":"Male","images":"0"}}]}
这是字符串格式,所以我想知道如何将这个字符串转换为 json 数组,我还不知道我必须如何使用输入流和所有这些实体,因此任何帮助将不胜感激。