我試圖得到一個JSON陣列的內部對象內部對象(我的術語可能是不正確的),看起來像這樣:安卓的Json得到
{
"News": {
"0": {
"name": "nytimes",
"fullName": "The New York Times",
"text": "@OwenPerry We heard from the owner of the house and corrected the article http://t.co/8GEgGy7",
"timestamp": "2011-08-15 12:20:36"
},
"1": {
"name": "HuffingtonPost",
"fullName": "Huffington Post",
"text": "Look out! New Zealand Skier chased by angry bulls - http://t.co/L0PZkx4",
"timestamp": "2011-08-15 12:19:04"
}
}
}
我的代碼來檢索內的物體看起來像這個:
JSONArray category = json.getJSONArray("News");
JSONArray innerobj = category.getJSONArray(0);
for (int i = 0; i < innerobj.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
JSONObject c = innerobj.getJSONObject(i);
map.put("id", String.valueOf(i));
map.put("name", c.getString("fullName") + "\n(#"
+ c.getString("name") + ") ");
map.put("text",
c.getString("text") + "\n - "
+ c.getString("timestamp"));
mylist.add(map);
}
任何想法,我在做什麼不正確?
目前出了什麼問題?這項工作的任何部分?你有沒有來自logcat的錯誤消息? – Pikaling