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']

Share:
2,360
Darwish Al-Neyadi
Author by

Darwish Al-Neyadi

Updated on December 06, 2022

Comments

  • Darwish Al-Neyadi
    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 a Map<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, like data["key"]["String"]?

    • Günter Zöchbauer
      Günter Zöchbauer over 5 years
      Please provide sample data and the code that shows what you tried and where you failed.