我正在尝试解析json响应,但是出现此错误,我不知道为什么。该错误发生在数据对象内部。因为当我删除对象时,它可以完美工作。我需要知道做错了什么。
class TripDetails {
String operatorId;
String title;
String body;
Data data;
TripDetails({this.operatorId, this.title, this.body, this.data});
TripDetails.fromJson(Map<String, dynamic> json) {
operatorId = json['operatorId'];
title = json['title'];
body = json['body'];
data = json['data'] != null ? new Data.fromJson(json['data']) : null;
}
}
class Data {
String clickAction;
String tripId;
String tripType;
String date;
String earning;
String distance;
String stores;
Data(
{this.clickAction,
this.tripId,
this.tripType,
this.date,
this.earning,
this.distance,
this.stores});
Data.fromJson(Map<String, dynamic> json) {
clickAction = json['click_action'];
tripId = json['tripId'];
tripType = json['trip_type'];
date = json['date'];
earning = json['earning'];
distance = json['distance'];
stores = json['stores'];
}
这是试图解析的数据。该问题发生在数据对象内部。
{
"operatorId": "W5u8Bz2oeIMM32I8ZSanreKvwLk2",
"title": "Hoole",
"body": "New Trip Request",
"data": {
"click_action": "FLUTTER_NOTIFICATION_CLICK",
"tripId": "12131131",
"trip_type": "trip",
"date":"12343325",
"earning":"123.54",
"distance":"123",
"stores":"[{\"id\":\"pnp1\",\"name\":\"Pick n Pay\",\"logo\":\"https://example.com\"}, {\"id\":\"woolies1\",\"name\":\"Woolworths\",\"logo\":\"https://example.com\"}]"
}
}
答案 0 :(得分:0)
更改此:
Data.fromJson(Map<String, dynamic> json) {
对此:
Data.fromJson(Map json) {