Json 获取问题:'_内部链接dhashmap<;字符串,动态>';不是类型为';列表<;动态>';
我试图从API中获取数据,但一直出现此错误 获取问题:“\u InternalLinkedHashMap”不是“List”类型的子类型 请告诉我如何修复此代码 省道模型Json 获取问题:'_内部链接dhashmap<;字符串,动态>';不是类型为';列表<;动态>';,json,api,flutter,rest,dart,Json,Api,Flutter,Rest,Dart,我试图从API中获取数据,但一直出现此错误 获取问题:“\u InternalLinkedHashMap”不是“List”类型的子类型 请告诉我如何修复此代码 省道模型 class ComprovanteModel { ComprovantesInfoModel jsonResponse; String error; ComprovanteModel({this.jsonResponse, this.error}); ComprovanteModel.fromJson(Ma
class ComprovanteModel {
ComprovantesInfoModel jsonResponse;
String error;
ComprovanteModel({this.jsonResponse, this.error});
ComprovanteModel.fromJson(Map<String, dynamic> json)
: jsonResponse = ComprovantesInfoModel.fromJson(json['json_response']),
error = '';
ComprovanteModel.withError(String errorValue)
: jsonResponse = null,
error = errorValue;
}
class ComprovanteInfoModel {
String clientFormalName;
int volumes;
int duration;
CheckpointsModel checkpoint;
ComprovanteInfoModel({
this.clientFormalName,
this.duration,
this.volumes,
this.checkpoint,
});
ComprovanteInfoModel.fromJson(Map<String, dynamic> json)
: clientFormalName = json['client_formal_name'],
checkpoint = CheckpointsModel.fromJson(json['checkpoint']),
volumes = json['volumes'],
duration = json['duration'];
}
class CheckpointModel {
int checkpointId;
String arrivalTime;
int status;
CheckpointModel({
this.checkpointId,
this.arrivalTime,
this.status,
});
CheckpointModel.fromJson(Map<String, dynamic> json)
: checkpointId = json['checkpoint_id'],
arrivalTime = json['arrival_time'],
status = json['status'];
}
class CheckpointsModel {
List<CheckpointModel> checkpoint;
CheckpointsModel({this.checkpoint});
CheckpointsModel.fromJson(List<dynamic> jsonList)
: checkpoint = jsonList.map((e) => CheckpointModel.fromJson(e)).toList();
}
我想访问检查点项,然后是资源项(我认为这与检查点的过程相同)。我用的是这个列表,但我觉得不对,我想用的是地图,但我不知道怎么用。请给我指路。- 更改此项:
ComprovanteModel.fromJson(Map<String, dynamic> json) : jsonResponse = ComprovantesInfoModel.fromJson(json['json_response']), error = '';
- 您告诉Flatter您将传递一个类型为
的对象,但在您发布的json中,List
不是一个列表,而是一个映射。但即使如此,这个映射只有一个检查点“checkpoint”:{
- 来回答你的最后一个问题
确实是一个地图列表。在您的代码中,您没有发布您的资源模型,但我假设您想要一个“资源”:[
列表,而不是
列表,它将如下所示:
class SingleResourceModel { String contentType; int serviceId; String content; String contentLabel; String uniqueCode; SingleResourceModel({ this.contentType, this.serviceId, this.content, this.contentLabel, this.uniqueCode }); SingleResourceModel.fromJson(Map<String, dynamic> json) : contentType = json['content_type'], serviceId = json['service_event_effect_id'], content = json['content']; contentLabel = json['content_label'], uniqueCode = json['user_effect_unique_code']; } class ListResourceModel { List<SingleResourceModel> resourcesList; ListResourceModel({this.resourcesList}); ListResourceModel.fromJson(List<Map<String, dynamic>> jsonList) : resourcesList = jsonList.map((e) => SingleResourceModel.fromJson(e)).toList(); }
现在,您应该准备好了。非常感谢MAAN!!!问题解决得很顺利!!非常感谢您!编码快乐:)ComprovanteModel.fromJson(Map<String, dynamic> json) : jsonResponse = ComprovantesInfoModel.fromJson(json['json_response'][0]), //added [0] here. error = '';
CheckpointsModel.fromJson(List<dynamic> jsonList) : checkpoint = jsonList.map((e) => CheckpointModel.fromJson(e)).toList(); }
class SingleResourceModel { String contentType; int serviceId; String content; String contentLabel; String uniqueCode; SingleResourceModel({ this.contentType, this.serviceId, this.content, this.contentLabel, this.uniqueCode }); SingleResourceModel.fromJson(Map<String, dynamic> json) : contentType = json['content_type'], serviceId = json['service_event_effect_id'], content = json['content']; contentLabel = json['content_label'], uniqueCode = json['user_effect_unique_code']; } class ListResourceModel { List<SingleResourceModel> resourcesList; ListResourceModel({this.resourcesList}); ListResourceModel.fromJson(List<Map<String, dynamic>> jsonList) : resourcesList = jsonList.map((e) => SingleResourceModel.fromJson(e)).toList(); }
class CheckpointModel { int checkpointId; String arrivalTime; int status; ListResourceModel resourcesList; CheckpointModel({ this.checkpointId, this.arrivalTime, this.status, this.resourcesList }); CheckpointModel.fromJson(Map<String, dynamic> json) : checkpointId = json['checkpoint_id'], arrivalTime = json['arrival_time'], status = json['status'], resourcesList= json['resources']; }
- 您告诉Flatter您将传递一个类型为