【发布时间】:2021-07-17 06:50:30
【问题描述】:
{
"count": 152,
"filters": {},
"competitions": [
{
"id": 2006,
"area": {
"id": 2001,
"name": "Africa",
"countryCode": "AFR",
"ensignUrl": null
},
"name": "WC Qualification",
"code": null,
"emblemUrl": null,
"plan": "TIER_FOUR",
"currentSeason": {
"id": 555,
"startDate": "2019-09-04",
"endDate": "2021-11-16",
"currentMatchday": 1,
"winner": null
},
"numberOfAvailableSeasons": 2,
"lastUpdated": "2018-06-04T23:54:04Z"
}
}
这是我的 JSON API,我如何访问“区域”中的数据以及“比赛”中的数据。
#i 能够从“竞赛”访问数据,下面是我的代码:
JSONObject jsonObject = new JSONObject(responseValue);
JSONArray jsonArray = jsonObject.getJSONArray("competitions");
competitionsModelList = new ArrayList<>();
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jitems = jsonArray.getJSONObject(i);
name = jitems.getString("name");
id = jitems.getInt("id");
code = jitems.getString("code");
emblemUrl = jitems.getString("emblemUrl");
plan = jitems.getString("plan");
numberOfSeasonAvailable = items.getInt("numberOfAvailableSeasons");
lastUpdated = jitems.getString("lastUpdated");
}
现在我想从“区域”访问数据。 谢谢
【问题讨论】:
-
使用 Gson 将 JSON 映射到对其建模的 Java 对象上,而不是尝试手动进行所有提取。
-
帮助..请发布一些代码片段