Reputation: 65
I have an error in prase JSON data API flutter, the is the response from API
{
"response": {
"message": "Loaction Found",
"responseCode": 0
},
"Loaction": {
"driver_id": 1,
"Latitude": "31.959727",
"longitude": "35.837615",
"time": "12/04/2020 16:09:33"
}
}
I made the model from the https://javiercbk.github.io/json_to_dart/
but I can't know how to prase the contents of JSON data, I try using the below code, but I didn't receive and data, can anyone help me ??
this is my all code:
https://github.com/mohmmed750/flutter-json/blob/master/json-flutter
Upvotes: 0
Views: 68
Reputation: 3313
Please remove this code
for (Map i in jsonData) {
_list.add(DriverLocation.fromJson(i));
}
And use this code instead
_list.add(DriverLocation.fromJson(jsonData));
Then you can print in the console using, to see the list items.
for (var i = 0; i < _list.length; i++) {
DriverLocation dl = _list[i];
print(dl.loaction.driverId);
}
Upvotes: 1
Reputation: 300
You don't need to parse the json with DriverLocation class. You can straight off get the Loaction
key from jsonData
and parse it with Loaction.fromJson()
directly.
Something like this:
var location = jsonData['Loaction'];
_list.add(Loaction.fromJson(location));
Code that I tried out - https://dartpad.dev/63fdc82ea0f6641698d42fcde47811f2
Hope this helps!
Upvotes: 1