【发布时间】:2021-07-03 14:46:43
【问题描述】:
我正在尝试从 API 获取数据,但我不断收到此错误。
获取问题:“_InternalLinkedHashMap
”不是“列表”类型的子类型
请告诉我如何修复此代码。
模型.dart
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();
}
API 响应:
{
"json_response": [
{
"client_formal_name": "",
"deadline": null,
"volumes": 1,
"duration": 5,
"depot_id": 20,
"service_id": 109856,
"georef_provider": "ap_geocoder",
"checkpoint": {
"checkpoint_id":,
"arrival_time": "",
"duration":,
"status": 1,
"event_id": 5,
"resources": [
{
"content_type": "PHOTO",
"service_event_effect_id": 58,
"content": "em+ndG6XtE2unp",
"content_label": "",
"user_effect_unique_code": ""
},
{
"content_type": "RECEPTOR_INFO",
"service_event_effect_id": 61,
"content": "{\"user_relationship_unique_code\":\"\",\"is_expected_receiver\":\"true\",\"document\":\"65979973000240\",\"name\":\"",\"description\":\"",\"id\":\"1\"}",
"content_label": "",
"user_effect_unique_code": "2"
}
],
"event_description": "",
"operation_date": "",
"obs": "",
"is_assistant": false,
"image": "{\"description\": \"Documento\", \"photo\": \""}"
},
"final_attendance_window_b": null
}
]
}
我想访问检查点项,然后是资源项(我认为它与检查点的过程相同)。我正在使用列表,但我认为不正确,我想使用地图,但我不知道如何使用。请告诉我一个方法。
【问题讨论】:
标签: json api flutter rest dart