我似乎无法获得 JSON 数组中的第二层。我想要的是,从类别中获取所有名称,然后我想通过意图将“论坛 id”发送到不同的活动。
如果有帮助,我按照本教程进行操作,并从这里获取我的 JSON 数组
JSON 数组的一部分
{
"categories": [{
"name": "Facepunch",
"forums": [{
"id": 6,
"name": "General Discussion",
"viewing": 217
}, {
"id": 60,
"name": "Fast Threads",
"viewing": 188
}, {
"id": 64,
"name": "Videos And Flash Movies and That Kind Of Crap",
"viewing": 239
}, {
"id": 403,
"name": "Mass Debate",
"viewing": 9
}, {
"id": 396,
"name": "Sensationalist Headlines",
"viewing": 455
}, {
"id": 51,
"name": "In The News Node",
"viewing": 100
}]
}]
}
我的部分代码
try {
// Getting Array of Contacts
categories = json.getJSONArray(TAG_CATEGORIES);
forums = json.getJSONArray(TAG_FORUMS);
// looping through All categories
for(int i = 0; i < categories.length(); i++){
JSONObject c = categories.getJSONObject(i);
// Storing each json item in variable
String CatName = c.getString(TAG_CATName);
// Phone number is agin JSON Object
JSONObject All_forums = forums.getJSONObject(i);
String forum_id = All_forums.getString(TAG_FORUMS_ID);
String forum_name = All_forums.getString(TAG_FORUMS_NAME);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_CATName, CatName);
map.put(TAG_FORUMS, forum_name);
// adding HashList to ArrayList
contactList.add(map);
}
} catch (JSONException e) {
e.printStackTrace();
}