读书人

android json string变换jsonarray 报

发布时间: 2012-06-20 20:37:21 作者: rapoo

android json string转换jsonarray 报错
post.setEntity(new UrlEncodedFormEntity(params,"utf-8"));

HttpResponse httpResponse = httpClient.execute(post);

if(httpResponse.getStatusLine().getStatusCode() == 200)
{
String result = EntityUtils.toString(httpResponse.getEntity(),"utf-8");

return result;
}

result = 02-13 12:12:04.011: INFO/System.out(951): ?[{"id":"2","user":"gc","psw":"okokok"}]

JSONArray array=new JSONArray(result);
这个地方报错

02-13 11:57:20.652: ERROR/test(568): org.json.JSONException: Value ? of type java.lang.String cannot be converted to JSONArray


[解决办法]
String jsonString = "{\"FLAG\":\"flag\",\"MESSAGE\":\"SUCCESS\",\"name\":[{\"name\":\"jack\"},{\"name\":\"lucy\"}]}";
JSONObject result = new JSONObject(jsonString);
JSONArray nameList = result.getJSONArray("name");


参考 http://blog.csdn.net/vincent_czz/article/details/7333977

读书人网 >Android

热点推荐