I'm trying to convert this json response to a dart model, but I can't figure out how to parse "standings" which is a double nested list. What im trying at the moment doesnt work (i thought i should access the first element in the higher list):
StandingLeague.fromJson(Map<String, dynamic> json) {
id = json['id'];
name = json['name'];
country = json['country'];
logo = json['logo'];
flag = json['flag'];
season = json['season'];
if (json['standings'] != null) {
standings = <Standing>[];
json['standings'][0].forEach((v) { standings?.add(v); });
}
}
Json response:
{
"league": {
"id": 39,
"name": "Premier League",
"country": "England",
"logo": "https://media.api-sports.io/football/leagues/39.png",
"flag": "https://media.api-sports.io/flags/gb.svg",
"season": 2022,
"standings": [
[
{
"rank": 1,
"team": {
"id": 42,
"name": "Arsenal",
"logo": "https://media.api-sports.io/football/teams/42.png"
},
"points": 18,
"goalsDiff": 10,
"group": "Premier League",
"form": "WLWWW",
"status": "same",
"description": "Promotion - Champions League (Group Stage)",
"all": {
"played": 7,
"win": 6,
"draw": 0,
"lose": 1,
"goals": {
"for": 17,
"against": 7
}
},
"home": {
"played": 3,
"win": 3,
"draw": 0,
"lose": 0,
"goals": {
"for": 8,
"against": 4
}
},
"away": {
"played": 4,
"win": 3,
"draw": 0,
"lose": 1,
"goals": {
"for": 9,
"against": 3
}
},
"update": "2022-09-18T00:00:00+00:00"
},
{
"rank": 2,
"team": {
"id": 50,
"name": "Manchester City",
"logo": "https://media.api-sports.io/football/teams/50.png"
},
"points": 17,
"goalsDiff": 17,
"group": "Premier League",
"form": "WDWWD",
"status": "same",
"description": "Promotion - Champions League (Group Stage)",
"all": {
"played": 7,
"win": 5,
"draw": 2,
"lose": 0,
"goals": {
"for": 23,
"against": 6
}
},
"home": {
"played": 3,
"win": 3,
"draw": 0,
"lose": 0,
"goals": {
"for": 14,
"against": 2
}
},
"away": {
"played": 4,
"win": 2,
"draw": 2,
"lose": 0,
"goals": {
"for": 9,
"against": 4
}
},
"update": "2022-09-18T00:00:00+00:00"
},
{
"rank": 3,
"team": {
"id": 47,
"name": "Tottenham",
"logo": "https://media.api-sports.io/football/teams/47.png"
},
"points": 17,
"goalsDiff": 11,
"group": "Premier League",
"form": "WWDWW",
"status": "same",
"description": "Promotion - Champions League (Group Stage)",
"all": {
"played": 7,
"win": 5,
"draw": 2,
"lose": 0,
"goals": {
"for": 18,
"against": 7
}
},
"home": {
"played": 4,
"win": 4,
"draw": 0,
"lose": 0,
"goals": {
"for": 13,
"against": 4
}
},
"away": {
"played": 3,
"win": 1,
"draw": 2,
"lose": 0,
"goals": {
"for": 5,
"against": 3
}
},
"update": "2022-09-18T00:00:00+00:00"
},
{
"rank": 4,
"team": {
"id": 51,
"name": "Brighton",
"logo": "https://media.api-sports.io/football/teams/51.png"
},
"points": 13,
"goalsDiff": 6,
"group": "Premier League",
"form": "WLWWD",
"status": "same",
"description": "Promotion - Champions League (Group Stage)",
"all": {
"played": 6,
"win": 4,
"draw": 1,
"lose": 1,
"goals": {
"for": 11,
"against": 5
}
},
"home": {
"played": 3,
"win": 2,
"draw": 1,
"lose": 0,
"goals": {
"for": 6,
"against": 2
}
},
"away": {
"played": 3,
"win": 2,
"draw": 0,
"lose": 1,
"goals": {
"for": 5,
"against": 3
}
},
"update": "2022-09-18T00:00:00+00:00"
},
{
"rank": 5,
"team": {
"id": 33,
"name": "Manchester United",
"logo": "https://media.api-sports.io/football/teams/33.png"
},
"points": 12,
"goalsDiff": 0,
"group": "Premier League",
"form": "WWWWL",
"status": "same",
"description": "Promotion - Europa League (Group Stage)",
"all": {
"played": 6,
"win": 4,
"draw": 0,
"lose": 2,
"goals": {
"for": 8,
"against": 8
}
},
"home": {
"played": 3,
"win": 2,
"draw": 0,
"lose": 1,
"goals": {
"for": 6,
"against": 4
}
},
"away": {
"played": 3,
"win": 2,
"draw": 0,
"lose": 1,
"goals": {
"for": 2,
"against": 4
}
},
"update": "2022-09-18T00:00:00+00:00"
},
{
"rank": 6,
"team": {
"id": 36,
"name": "Fulham",
"logo": "https://media.api-sports.io/football/teams/36.png"
},
"points": 11,
"goalsDiff": 1,
"group": "Premier League",
"form": "WLWLW",
"status": "same",
"description": null,
"all": {
"played": 7,
"win": 3,
"draw": 2,
"lose": 2,
"goals": {
"for": 12,
"against": 11
}
},
"home": {
"played": 3,
"win": 2,
"draw": 1,
"lose": 0,
"goals": {
"for": 7,
"against": 5
}
},
"away": {
"played": 4,
"win": 1,
"draw": 1,
"lose": 2,
"goals": {
"for": 5,
"against": 6
}
},
"update": "2022-09-18T00:00:00+00:00"
},
{
"rank": 7,
"team": {
"id": 49,
"name": "Chelsea",
"logo": "https://media.api-sports.io/football/teams/49.png"
},
"points": 10,
"goalsDiff": -1,
"group": "Premier League",
"form": "WLWLD",
"status": "same",
"description": null,
"all": {
"played": 6,
"win": 3,
"draw": 1,
"lose": 2,
"goals": {
"for": 8,
"against": 9
}
},
"home": {
"played": 3,
"win": 2,
"draw": 1,
"lose": 0,
"goals": {
"for": 6,
"against": 4
}
},
"away": {
"played": 3,
"win": 1,
"draw": 0,
"lose": 2,
"goals": {
"for": 2,
"against": 5
}
},
"update": "2022-09-18T00:00:00+00:00"
}
]
]
}
}