[英]get JSONObject from JSONArray
for(int i = 0; i < ja.length(); i++){
JSONObject jo = ja.getJSONObject(i);
Resources.show(jo);
}
In the above code I want to fetch the json object from json array. 在上面的代码中,我想从json数组中获取json对象。 But I'm getting an error
但是我出错了
org.json.JSONException: JSONArray[0] is not a JSONObject.
at org.json.JSONArray.getJSONObject(JSONArray.java:343)
at webutilities.Try.main(JSON.java:50)
BUILD SUCCESSFUL (total time: 0 seconds) 建立成功(总时间:0秒)
What else are the methods to fetch a json object from json array. 还有什么方法可以从json数组中获取json对象。
Try 尝试
System.out.println(ja.get(i).getClass().toString());
to find out what kind of object is within your JSONArray. 找出您的JSONArray中包含哪种对象。
Eg if you have Strings in there, simply use: 例如,如果您有Strings,只需使用:
ja.getString(i)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.