Reputation: 55
Am trying to get data from an API but I keep getting the error above . Here is how my API response is structured
{"cards":{"TOTAL_PERFORMED":0,"TOTAL_TO_BE_PERFORMED":0,"START_DATE":1619042400,"END_DATE":1619042400}}
And here is how am trying to get the data
Future<Map<List,dynamic>>cards_daily_request()async{
var apiUrl = "https:/s/Dashboard/cards/daily/$rvcid";
var response= await http.get(Uri.encodeFull(apiUrl),headers: {"Authorization":"$token"});
List data;
var extractdata=await json.decode(response.body);
data=await extractdata["cards"];
print(data[0]);
}
Any idea what am doing wrong?
Upvotes: 0
Views: 54
Reputation: 1010
The response is a map and not a List In json lists are defined with square brackets [ ]
Check Json structure #3 : Simple Nested structures In this article
https://link.medium.com/XVauCvELEfb
In short You need an object for the json and object for the card with some factory to map it from json
Upvotes: 1