解析android中的JSON响应" org.json.JSONObject类型的响应无法转换为JSONArray"

时间:2014-12-28 09:39:33

标签: java android json

我看到周围有很多问题,但我想我错过了一个我无法找到的细节。

我收到的字符串作为响应包含在以下错误中:

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");

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:1)

我看到的唯一JSONArray是结果键。您必须使用结果键,或者您需要getJSONObject() - Method,如上所述的gio。