当前位置: 代码迷 >> Android >> android json string变换jsonarray 报错
  详细解决方案

android json string变换jsonarray 报错

热度:42   发布时间:2016-05-01 20:57:37.0
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
  相关解决方案