我有一個JSON響應異常而轉換「JSONArray不能被轉換爲JSONObject的錯誤」
{"as_of":"2013-04-22T19:50:41Z","trends":[{"events":null,
"query":"%23RhymeATweepsName","url":"http:\/\/twitter.com\/search?
q=%23RhymeATweepsName","promoted_content":null,
"name":"#RhymeATweepsName"},
{"events":null,"query":"%23EarthDayPK","url":
"http:\/\/twitter.com\/search?
=%23EarthDayPK","promoted_content":null,"name":
"#EarthDayPK"}],"locations":
[{"woeid":*******,"name":"********"}],"created_at":"2013-04-22T19:38:16Z"}
,我用下面的代碼
jArray = new JSONArray(result);
JSONObject post = null;
for (int ii = 0; ii < jArray.length(); ii++) {
post = jArray.getJSONObject(ii);
String name = post.getJSONObject("trends").getString("name") + "\n";
}
}
解析它,但它拋出異常「JSONArray不能被轉換爲JSONObject錯誤「
''trends''是一個數組的異常狀態。 – harism 2013-04-22 19:57:25
是的。方案? – 2013-04-22 20:00:35
@ExtremeProgrammer我猜在getJSONObject方法的某處有一個getJSONArray方法? – 2013-04-22 20:01:31