簡體   English   中英

從JSONArray獲取JSONObject

[英]get JSONObject from JSONArray

for(int i = 0; i < ja.length(); i++){
            JSONObject jo = ja.getJSONObject(i);
            Resources.show(jo);
}

在上面的代碼中,我想從json數組中獲取json對象。 但是我出錯了

org.json.JSONException: JSONArray[0] is not a JSONObject.
at org.json.JSONArray.getJSONObject(JSONArray.java:343)
at webutilities.Try.main(JSON.java:50)

建立成功(總時間:0秒)

還有什么方法可以從json數組中獲取json對象。

嘗試

System.out.println(ja.get(i).getClass().toString());

找出您的JSONArray中包含哪種對象。

例如,如果您有Strings,只需使用:

ja.getString(i)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM