【发布时间】:2021-05-13 15:57:26
【问题描述】:
我正在尝试弄清楚如何在 Flutter 中解码以下 JSON。
https://covid.ourworldindata.org/data/owid-covid-data.json
我尝试了以下结构,但它不起作用。
@JsonSerializable()
class StatisticsResponse {
Map<String, Country> data;
//List<Country> data;
StatisticsResponse({this.data});
factory StatisticsResponse.fromJson(Map<String, dynamic> json) =>
_$StatisticsResponseFromJson(json);
}
@JsonSerializable()
class Country {
String continent;
String location;
int population;
//Map<String, Data> data;
List<Data> data;
Country({this.continent, this.location, this.population, this.data
});
factory Country.fromJson(Map<String, dynamic> json) =>
_$CountryFromJson(json);
}
【问题讨论】:
-
请您详细说明“不起作用”是什么意思?
-
没有运行时错误。字段 StatisticsResponse.data 只是 NULL