“A JSONArray text must start with '[' at character 1 of null”

匿名 (未验证) 提交于 2019-12-03 02:38:01

问题:

Just wondering what that error could mean? I get it from the following code..

 try{     JSONArray jArray = new JSONArray(result);     for(int i=0;i<jArray.length();i++){             JSONObject json_data = jArray.getJSONObject(i);             Log.i("log_tag","id: "+json_data.getInt("id")+                     ", name: "+json_data.getString("name")+                     ", sex: "+json_data.getInt("sex")+                     ", birthyear: "+json_data.getInt("birthyear")             );     } } }catch(JSONException e){     Log.e("log_tag", "Error parsing data "+e.toString()); } 

回答1:

Result is null, apparently. Or it simply does not start with [. Print it out before calling JSONArray to see.

Also take a look at the JSONArray source. It is expecting JavaScript array syntax, e.g.:

['this', 'is', 'array', 'syntax']



回答2:

text.trim(); text.trim();

Text is the json file or string , do this at least two times one after another will resolve the problem 99.9%.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!