I am new to flutter. I have following code. when i Map response body it gives error.
Expected a value of type 'Map<dynamic, dynamic>', but got one of type 'List' code is as below. I want to print(data["id"]);
var response = await http.post(url, body: mpost); // messageBox(context, response.body, response.body, "ok"); Map data = jsonDecode(response.body); print(data["id"]);
Your response.body is returned as List.
response.body
List
To get the id, you can use for-loop.
for-loop
for(var i in jsonDecode(response.body)){ print(i["id"]); }
1.4m articles
1.4m replys
5 comments
56.9k users