我想知道如何從服務器的HTTP響應轉換成合適的可解析JSON陣列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數組,我還不知道我是如何必須使用輸入流和所有這些實體,因此任何幫助不勝感激。
HTTP兩行://www.androidcompetenc ycenter.com/2009/10/json-parsing-in-android/ –