Retrieve value from Map<String, dynamic> after getting it from an API
2,360
You can use json.decode on your data
Example :
var response = await /* httpcall */
var data = json.decode(response.body);
Depending on the structure of your response you might have to change the field that you json encode, but at least you can now use data['foo']['bar']
Author by
Darwish Al-Neyadi
Updated on December 06, 2022Comments
-
Darwish Al-Neyadi over 1 year
I'm trying to get a value from an API and usually I get it through a list and just use an index and the String to get the info I need (e.g.
data[index]["String"]
), however this API sends aMap<String, dynamic>
and I used the key to retrieve part of the Map (data["key"]
}) but I am trying to be more specific in the value. Is there a way to get the exact value, likedata["key"]["String"]
?-
Günter Zöchbauer over 5 yearsPlease provide sample data and the code that shows what you tried and where you failed.
-