Having an issue with my flutter project parsing a json response and returning null.
Trying to receive the latitude and longitude values of an address I input. When I print out the jsonresponse variable I get the correct data, but when I try to parse the json response, both lat and lng, result in null. What am I missing?
part of void method to retreive lat/lng:
var response = await http.get(request);
var jsonresponse = response.body;
Location location = Location.fromJson(jsonDecode(jsonresponse));
print(location.lat);
print(location.lng);
Location class to parse json:
class Location {
double lat;
double lng;
Location({this.lat, this.lng});
Location.fromJson(Map<String, dynamic> json) {
lat = json['lat'];
lng = json['lng'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['lat'] = this.lat;
data['lng'] = this.lng;
return data;
}
}
Jsonresponse.body:
"results": [
{
"location": {
"lat": 35.2323243,
"lng": -80.234353
}}]