Search code examples
jsondartflutterdecode

get String from nested Map in dart


My Map:

{Info: {name: Austin, Username: austinr}}

I'm using this line to get the myName variable to be set as "Austin"

String myName = map["name"] as String;

However.. this line seems to set the string "myName" to null. just looking for a way to extract my name and Username from the map

Thanks


Solution

  • I am able to run the following code successfully.

     var map =  {"Info":{"name": "Austin", "Username": "austinr"}}; 
     String myString = map["Info"]["name"] as String;
     print(myString);
    

    The output is Austin as expected. Please try this.