I have an API, every time when I call it. It returns with a different number of keys.
Sometimes:
{
"json":[
"example",
"example1"
]
}
Other times:
{
"json":[
"example",
"example1",
"example2"
]
}
How can I count how many are there in a map?
CodePudding user response:
once you get your response. you can use
final map = jsonDecode(data) as Map<dynamic, dynamic>?;
print(map?.length); // items on root 1
final response = jsonDecode(data)["json"] as List?;
print(response?.length);