我試圖解析我的JSON數據,看起來像下面的數據。 我已經成功了一些字段,但我試圖在「條款」下的「類別」下的「0」下獲得「名稱」。我如何使用Gson Library對嵌套的JSON對象進行排序?
[
{
"ID": 1710,
"status": "publish",
"type": "post",
"content": "Lorem ipsum",
"parent": null,
"format": "standard",
"modified_tz": "UTC"
},
"featured_image": {
"ID": 1713,
"title": "km",
"status": "inherit",
"type": "attachment",
}
}
}
}
},
"terms": {
"category": [ <<<<---AM REFERENCING HERE--->>>>>
{
"ID": 2,
"name": "Entertainment",
"slug": "entertainment",
"taxonomy": "category",
"parent": null,
"count": 30,
}
]
}
}
]
我這是怎麼分析的數據:
List<Object> list = (List) new Gson.fromJson(response, List.class);
List<String, Object> mapPost = list.get(index);
List<String, Object> terms = (Map<String, Object>) mapPost.get("terms");
List<String, Object> category= (Map<String, Object>) terms.get("category");
List<String, Object> zero= (Map<String, Object>) category.get("0");
String tag = (String) zero.get("name");
普萊斯幫助我什麼我做錯了什麼?
它應該是'category.get(0)'。 '0'是該數組的索引,而不是json的密鑰 – akash93
這是我得到的錯誤消息: –
'E/AndroidRuntime:致命例外:主要 進程:example.example.com,PID:13804 java.lang。 ClassCastException:java.util.ArrayList不能轉換爲java.util.Map' –