gpt4 book ai didi

json - Flutter/Dart 错误 - NoSuchMethodError : Class '_InternalLinkedHashMap' has no instance method 'map' with matching arguments

转载 作者:行者123 更新时间:2023-12-03 03:24:04 37 4
gpt4 key购买 nike

我在 Json 反序列化后收到错误 cookbook

NoSuchMethodError: Class '_InternalLinkedHashMap<String, dynamic>' has no instance method 'map' with matching arguments.

捆绑类

class Bundle {
String resourceType;
String id;
String type;
int total;
List<Link> link;
List<Entry> entry;

Bundle(
{this.resourceType,
this.id,
this.type,
this.total,
this.link,
this.entry});

factory Bundle.fromJson(Map<String, dynamic> json) {
return Bundle(
resourceType : json['resourceType'],
id : json['id'],
type : json['type'],
total : json['total'],
);
}

代码:

    try {
await parsePerson(resultString);
} catch (e) {
print('Bundlelist Error: $e');
}

Future<List<Bundle>> parsePerson(String body) async {
List<Bundle> bundleList = [];
try {
final parsed = json.decode(body);
bundleList = parsed.map<Bundle>((json) => Bundle.fromJson(json)).toList;
} catch (e) {
print('FutureError: $e');
}
return bundleList;
}

我的结果字符串(部分):完整的 json 是 here .

{"resourceType":"Bundle","id":"f26779b4-5c3c-4c52-83b4-c689516a6a08","type":"searchset","link":[{"relation":"self","url":"https://fhir-open.sandboxcerner.com/dstu2/0b8a0111-e8e6-4c26-a91c-5069cbc6b1ca/Patient?name=b\u0026_count=20"},{"relation":"next","url":"https://fhir-open.sandboxcerner.com/dstu2/0b8a0111-e8e6-4c26-a91c-5069cbc6b1ca/Patient?-pageContext=7018d2bc-6be4-48e1-b8a4-a40f4e98c98c\u0026-pageDirection=NEXT"}],"entry":[{"fullUrl":"https://fhir-open.sandboxcerner.com/dstu2/0b8a0111-e8e6-4c26-a91c-5069cbc6b1ca/Patient/6160015","resource":{"resourceType":"Patient","id":"6160015","meta":{"versionId":"0","lastUpdated":"2019-07-08T20:37:03.000Z"},"text":{"status":"generated","div":"\u003Cdiv\u003E\u003Cp\u003E\u003Cb\u003EPatient\u003C/b\u003E\u003C/p\u003E\u003Cp\u003E\u003Cb\u003EName\u003C/b\u003E: 111d3fcaffb244b2b207c07ffa5a14, bf607a7f1f284e8aa3559d52249bc7\u003C/p\u003E\u003Cp\u003E\u003Cb\u003EDOB\u003C/b\u003E: Mar 15, 1936\u003C/p\u003E\u003Cp\u003E\u003Cb\u003EAdministrative Gend

我尝试了这里的各种建议,包括:

final parsed = jsonDecode(body).cast<Map<String, dynamic>>();

返回

NoSuchMethodError: Class '_InternalLinkedHashMap<String, dynamic>' has no instance method 'cast' with matching arguments.

我完全不知道接下来要尝试什么。

最佳答案

您需要一个数组,但您的响应是一个映射

关于json - Flutter/Dart 错误 - NoSuchMethodError : Class '_InternalLinkedHashMap<String, dynamic>' has no instance method 'map' with matching arguments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59674491/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com