如何将以下JSON文件处理到LatLong列表中,我已经看过很多教程,但是无法正常工作,我必须列出以下纬度和经度点
'''
{
"snappedPoints": [
{
"location": {
"latitude": -35.2784167,
"longitude": 149.1294692
},
"originalIndex": 0,
"placeId": "ChIJoR7CemhNFmsRQB9QbW7qABM"
},
{
"location": {
"latitude": -35.280321693840129,
"longitude": 149.12908274880189
},
"originalIndex": 1,
"placeId": "ChIJiy6YT2hNFmsRkHZAbW7qABM"
}
]
}
'''
答案 0 :(得分:0)
你好,刚到这个网站:
选择“ Dart”语言,它将为您创建类!
import 'package:meta/meta.dart';
import 'dart:convert';
SnappedPoints snappedPointsFromJson(String str) => SnappedPoints.fromJson(json.decode(str));
String snappedPointsToJson(SnappedPoints data) => json.encode(data.toJson());
class SnappedPoints {
final List<SnappedPoint> snappedPoints;
SnappedPoints({
@required this.snappedPoints,
});
factory SnappedPoints.fromJson(Map<String, dynamic> json) => SnappedPoints(
snappedPoints: List<SnappedPoint>.from(json["snappedPoints"].map((x) => SnappedPoint.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"snappedPoints": List<dynamic>.from(snappedPoints.map((x) => x.toJson())),
};
}
class SnappedPoint {
final Location location;
final int originalIndex;
final String placeId;
SnappedPoint({
@required this.location,
@required this.originalIndex,
@required this.placeId,
});
factory SnappedPoint.fromJson(Map<String, dynamic> json) => SnappedPoint(
location: Location.fromJson(json["location"]),
originalIndex: json["originalIndex"],
placeId: json["placeId"],
);
Map<String, dynamic> toJson() => {
"location": location.toJson(),
"originalIndex": originalIndex,
"placeId": placeId,
};
}
class Location {
final double latitude;
final double longitude;
Location({
@required this.latitude,
@required this.longitude,
});
factory Location.fromJson(Map<String, dynamic> json) => Location(
latitude: json["latitude"].toDouble(),
longitude: json["longitude"].toDouble(),
);
Map<String, dynamic> toJson() => {
"latitude": latitude,
"longitude": longitude,
};
}