您可以使用this创建模型
// To parse this JSON data, do
//
// final location = locationFromJson(jsonString);
import 'dart:convert';
List<Location> locationFromJson(String str) => List<Location>.from(json.decode(str).map((x) => Location.fromJson(x)));
String locationToJson(List<Location> data) => json.encode(List<dynamic>.from(data.map((x) => x.toJson())));
class Location {
Location({
this.pollId,
this.long,
this.lat,
this.speed,
this.isGpsAvailable,
this.status,
this.ign,
this.distance,
this.direction,
});
String pollId;
double long;
double lat;
int speed;
bool isGpsAvailable;
String status;
bool ign;
double distance;
int direction;
factory Location.fromJson(Map<String, dynamic> json) => Location(
pollId: json["PollId"],
long: json["Long"].toDouble(),
lat: json["Lat"].toDouble(),
speed: json["Speed"],
isGpsAvailable: json["IsGPSAvailable"],
status: json["Status"],
ign: json["Ign"],
distance: json["Distance"].toDouble(),
direction: json["Direction"],
);
Map<String, dynamic> toJson() => {
"PollId": pollId,
"Long": long,
"Lat": lat,
"Speed": speed,
"IsGPSAvailable": isGpsAvailable,
"Status": status,
"Ign": ign,
"Distance": distance,
"Direction": direction,
};
}
然后使用futurebuilder和listview来获取响应
FutureBuilder(
future: _future,
builder: (context, AsyncSnapshot<List<Location>> snapshot) {
return snapshot.data?.length == 0
? const Center(
child: Text("No Item"),
)
: ListView.builder(
shrinkWrap: true,
itemBuilder: (context, index) {
final data = snapshot.data[index];
print(data.long, data.lat);
// return UI
},
itemCount: snapshot.data?.length ?? 0,
);
},
)