异常:我投放回复时发生NoSuchMethodError

时间:2019-05-15 12:27:55

标签: flutter casting

我是新手,我想在列表视图中获取列表。我对此进行了很多搜索,但没有找到任何东西。当我尝试转换API的响应并且列表视图什么都没有显示时,发生异常。

例外:            Exception: NoSuchMethodError: Class '_InternalLinkedHashMap<String, dynamic>' has no instance method 'map' with matching arguments. I/flutter (21020): Receiver: _LinkedHashMap len:2 I/flutter (21020): Tried calling: map<Post>(Closure: (dynamic) => Post) I/flutter (21020): Found: map<K2, V2>((K, V) => MapEntry<K2, V2>) => Map<K2, V2>

  final response = await client.get('http:url');

  return compute(parsePosts, response.body);
}

List<Post> parsePosts(String responseBody) {
  final parsed = json.decode(responseBody).cast<Map<String, dynamic>>();

  return parsed.map<Post>((json) => Post.fromJson(json)).toList();
}

我的JSON就是这样

     {
    "status": "1",
    "category": [
        "Artificial Intelligence",
        "big data",
        "Cyber Security",
        "Data Science",
        "Software Development"
    ]
} 

我想在Flutter的列表视图中显示列表数据。如果您有任何疑问或关于代码的问题,可以问我。希望我能从这个社区得到最好的解决方案。 预先感谢。

0 个答案:

没有答案