Categories
Mastering Development

flutter problem in json parsing of dynamic key values

Following is the output of my JSON

{
    "success": true,
    "data": {
        "ones": [{
                "id": "2",
                "username": "LM10002"
            },
            {
                "id": "6",
                "username": "LM10006"
            }
        ],
        "twos": [{
                "id": "3",
                "username": "LM10003"
            },
            {
                "id": "8",
                "username": "LM10008"
            }
        ],
        "threes": [{
            "id": "4",
            "username": "LM10004"
        }],
        "fours": [{
                "id": "5",
                "username": "LM10005"
            },
            {
                "id": "14",
                "username": "GT10014"
            }
        ]
    }
}

Here the keys ones, twos, threes, fours are dynamic key values
I tried parsing and able to get the values of

  DownLineModel({this.success, this.data});
  DownLineModel.fromJson(Map<String, dynamic> json) {
    success = json['success'];
    data = json['data'];
    print(data);

how can i parse the json and find the key terms and again parse it.

Leave a Reply

Your email address will not be published. Required fields are marked *