簡體   English   中英

在Android中解析JSON響應“無法將org.json.JSONObject類型的響應轉換為JSONArray”

[英]Parse JSON response in android “response of type org.json.JSONObject cannot be converted to JSONArray”

我已經看到周圍有很多問題,但是我想我缺少一個我找不到的細節。

我作為響應得到的字符串包含在以下錯誤中:

12-28 10:25:14.402: W/System.err(2133): org.json.JSONException: Value
{"status":"ok","userTier":"developer","total":1722082,"startIndex":1,"pageSize":5,"currentPage":1,"pages":344417,"orderBy":"newest",
"results":[{"webTitle":"AirAsia flight loses contact with air traffic control between Indonesia and Singapore","webPublicationDate":"2014-12-28T09:06:55Z","sectionName":"World news","sectionId":"world","id":"world\/live\/2014\/dec\/28\/airasia-flight-loses-contact-with-air-traffic-control-on-route-from-indonesia-to-singapore","webUrl":"
...  at response of type org.json.JSONObject cannot be converted to JSONArray

我的代碼是

JSONObject jObject = new JSONObject(result);// result is the sting response presented above
JSONArray jArray = jObject.getJSONArray("response");

response鍵是JSONObject,您需要使用getJSONObject代替當前方法。

我看到的唯一JSONArray是結果鍵。 您必須使用result鍵,或者需要使用getJSONObject()-Method,如gio所述。

暫無
暫無

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

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