I’m getting a json response in the format
"category1": {
"Winter": [
"Woolen Clothes",
"Rain Coats",
"sweater"
]
},
"category2": {
"Summer": [
"Sun Glass",
"Cotton Clothes",
"Ice Creams"
]
},
How can i convert this to an object. I have tried the following
Map<String,List<String>> category1;
Map<String,List<String>> category2;
category1: Map<String,List<String>>.from(json["category1"] ?? [].map((x) => x));
category2: Map<String,List<String>>.from(json["category2"] ?? [].map((x) => x));
but it throws the following error
type 'MappedListIterable<dynamic, dynamic>' is not a subtype of type 'Map<dynamic, dynamic>'
what is the correct method to parse the map??
3
Answers
The first thing you should do is create a model that is in charge of mapping the json. I recommend that you use this page https://app.quicktype.io/.
on the left side you paste what the json is that you want to map and on the right you choose dart as the language to generate the model,
r last you must call that model and the function from map and you pass the json as a parameter.