How parse a json that contains list of different objects in Dart

Viewed 31

how can I map this json in Dart? This json is the response.data of a get request with Dio library in Flutter.

[
 {
    "getPlayersFilterResult": 
    {
        "Players": [{p1},{p2},..]
    }
 },

 {
    "getTeamsFilterResult": 
    {
        "Teams": [{t1},{t2},..]
    }
 }]

That json is a list with two different object (with different attributes).

1 Answers

Try this:

List<Map<String, dynamic>> _result = response.data as List<Map<String, dynamic>>;

List players = _result[0]['getPlayersFilterResult']['Players'];
List teams = _result[1]['getTeamsFilterResult']['Teams'];
Related