【发布时间】:2021-05-04 05:20:30
【问题描述】:
我不想像 (json["features"][0] 或 json["features"][1]) 这样索引 json。我怎样才能把它变成一个列表或其他东西?
我的代码如下:
class Other {
String title;
double mag;
String title1;
double mag1;
String title2;
double mag2;
Other({this.mag, this.title, this.mag1, this.title1, this.mag2, this.title2});
factory Other.fromJson(Map<String, dynamic> json) {
return Other(
title: json["features"][0]["properties"]["place"],
mag: json["features"][0]["properties"]["mag"],
title1: json["features"][1]["properties"]["place"],
mag1: json["features"][1]["properties"]["mag"],
title2: json["features"][2]["properties"]["place"],
mag2: json["features"][2]["properties"]["mag"],
);
}
}
json 数据在这里:https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_hour.geojson
【问题讨论】:
标签: android json list flutter mobile