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

标签 json flutter dart deserialization

我在 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/

相关文章:

Firebase 电话身份验证在 Flutter 应用程序中不起作用,无论是在 iOS 模拟器还是在真实设备中

flutter - 从 Flutter 项目运行 android 项目,具有不健全的空安全

FirebaseAnimatedList 实时改变内容

dart - 当我只设置一次时,我的变量会自动更新。为什么会这样?

javascript - 如何验证 g-captcha-response?

php - 如何以 .JSON 文件格式存储 MySQL 数据?

php - 字典中的 JSON 编码字典未使用 AFNetworking 正确反序列化

android - 在 Flutter 中为 DropdownMenu 使用枚举和 ValueNotifier

dart - 如何在 Polymer.dart 0.5 中访问 map 值/遍历 map

python - 尝试从 json 解析值时出现类型错误