taha
taha

Reputation: 109

How To Fetch All Available JSON Data inside a index of JSON data

I am trying to fetch the name and price from JSON data as shown below but it only gives me one name and one price as I have to use the index to fetch a particular data how can I fetch all the available name and price from the JSON data

here is my function

void getData() async {
http.Response response = await http.get(
    "API LINK");
if (response.statusCode == 200) {
  String data = response.body;

  var decodeData = jsonDecode(data);

  var name = decodeData['entry'][0]['gsx\$name'];
  var price = decodeData['entry'][0]['gsx\$price'];

  print(name);
  print(price);
}

}

enter image description here

Upvotes: 0

Views: 77

Answers (2)

Alperen Ekin
Alperen Ekin

Reputation: 318

decodeData.forEach((key,value){
    print(value['gsx\$name']); 
    print(value['gsx\$price']);
})

This can help.

Upvotes: 0

Elfor
Elfor

Reputation: 587

you can just use a for loop

for(var i = 0; i < decodeData['entry'].length; i++){
  print(decodeData['entry'][i]['gsx\$name']);
  print(decodeData['entry'][i]['gsx\$price']);
}

Upvotes: 1

Related Questions