Decoding JSON in Flutter

169
Var _response = JsonDecode(response.body) ; 
print(_response[0]['key1']);
Share:
169
Admin
Author by

Admin

Updated on December 07, 2022

Comments

  • Admin
    Admin over 1 year

    REST_API provides a JSON Object like this:

    [
       {
          "key1":"value1"
          "key2":"value2"
       }
    ]
    

    Question: How can I Parse that with Dart? I do not get it running. My main problem is that any approach with json.decode will remove all annotations so strings are no longer strings.

    Sure I could cut of the square brackets at the beginning and at the end but thats not what i would call good coding.

    Maybe some of you can help ;-)

    Have a great day!