这个问题在这里已经有答案了:
如何在android中解析json[重复](3个答案)
两天前关门了。
{
"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"
}
}
这是我的JSONAPI,我如何访问来自“区域”的数据以及来自“竞赛”的数据。
我可以访问“竞赛”的数据,下面是我的代码:
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");
}
现在我想从“区域”访问数据。谢谢您
2条答案
按热度按时间v1l68za41#
您可以从中创建一个新的json对象
jitems
:0sgqnhkj2#
您可以按以下方式访问