I get response from backend:
{"measurements": {
"pm10": {
"name": "pm10",
"value": 20.8647,
"unit": "µg/m³"
},
"pm25": {
"name": "pm10",
"value": 20.8647,
"unit": "µg/m³"
},
"o2": {
"name": "pm10",
"value": 20.8647,
"unit": "µg/m³"
}
},
"station": {
"city": "{cityName}",
"name": "{locationName}",
"latitude": "54.353336",
"longitude": "18.635283"
}
}
This is what I got at this moment:
class Pollutions {
Pollutions.fromJsonMap(Map<String, dynamic> map):
measurements = Measurements.fromJsonMap(map["measurements"]),
station = Station.fromJson(map["station"]);
Map<String, Pollution> measurements;
Station station;
Map<String, dynamic> toJson() {
final data = Map<String, dynamic>();
data['measurements'] = measurements == null ? null : measurements.jsonDecode(measurements);
data['station'] = station == null ? null : station.toJson();
return data;
}
}
and in measurements I can get other values and I don't know anything about they names, it could be o2, o3, not only pm10 etc. Can I parse this measurements to map key-value, where key will be pm10, something like that: Map?
How should looks Pollutions.fromJsonMap
and toJson
methods for map?