I have a complex API which has a json array. i want to display the details in the JSON in a flutter listView. The following is my json
{
"hours": [
{
"time": "2021-03-23T00:00:00+00:00",
"waveHeight": {
"icon": 1.35,
"meteo": 1.25,
"noaa": 1.28,
"sg": 1.25
}
},
{
"time": "2021-03-23T00:00:00+00:00",
"waveHeight": {
"icon": 1.35,
"meteo": 1.25,
"noaa": 1.28,
"sg": 1.25
}
},
],
}
This is the fetch data function
void getJsonData() async {
String url2 =
'https://api.stormglass.io/v2/weather/point?lat=5.9774&lng=80.4288¶ms=waveHeight&start=2021-03-23&end2021-03-24';
String apiKey =
'sxascdsvfdyhujn5787654gb-7a54-11eb-8302-0242ac130002';
print('0');
try {
Response response = await get(Uri.parse(url2),
headers: {HttpHeaders.authorizationHeader: apiKey});
var jsonData = jsonDecode(response.body);
List data = jsonData["hours"];
data.forEach((element) {
Map obj = element;
Map wave = obj['waveHeight'];
String time = obj['time'];
print(time);
double icon = wave['icon'];
print(icon);
});
} catch (e) {
print(e);
}
}
All the JSON data are successfully fetched and displayed in the console. But I want to display the data in a flutter ListView. How can i do that?