Home > front end >  How can i loop through an array of objects in flutter
How can i loop through an array of objects in flutter

Time:06-17

Here is my code

Future ppp() async {
    var url ='my url here';
    final response = await http.get(Uri.parse(url));
    return response;
  }
   var data = await ppp();
   var id = json.decode(json.encode(data.body));
   print(id);

when i print, this is the result

[{"id":"168"}]

What i want to access is the 168

CodePudding user response:

Try this,

var id = json.decode(json.encode(data.body));
print(id[0]["id"].toString());

CodePudding user response:

var parsedJson = json.decode(json.encode(data.body));
var id = parsedJson[0]['id']

Dunno why you encode and decode body

  • Related