首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

android json string变换jsonarray 报错

2012-06-20 
android json string转换jsonarray 报错post.setEntity(new UrlEncodedFormEntity(params,utf-8))HttpR

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

热点排行