我是Ffltter的新手,我try 运行一个GitHub项目,但得到一个错误,如type list dynamic is not a subtype of type list int where(类型列表动态不是类型列表int的子类型).Github Link

Error Line

List<int> genreIds;

MediaItem._internalFromJson(Map jsonMap, {MediaType type: MediaType.movie})
      :
        type = type,
        id = jsonMap["id"].toInt(),
        voteAverage = jsonMap["vote_average"].toDouble(),
        title = jsonMap[(type == MediaType.movie ? "title" : "name")],
        posterPath = jsonMap["poster_path"] ?? "",
        backdropPath = jsonMap["backdrop_path"] ?? "",
        overview = jsonMap["overview"],
        releaseDate = jsonMap[(type == MediaType.movie
            ? "release_date"
            : "first_air_date")],

        genreIds = jsonMap["genre_ids"];//in this line


}

Above code File

任何帮助我们都将不胜感激,提前谢谢您.

推荐答案

Change

genreIds = jsonMap["genre_ids"];

to

genreIds = jsonMap["genre_ids"].cast<int>();

types in JSON maps or lists don't have concrete generic types. genreIds requires a List<int> not a List (or List<dynamic>), therefore you need to bring the value to its required type before you can assign it.

If you haven't seen this error earlier for the same code, then it's probably because you upgraded to a Dart version where --preview-dart-2 became the default (it was opt-in previously)

Json相关问答推荐

如何使用表键名称GROUP_BY

Vega图表计数聚合如果数据值为空数组则不显示任何内容,如何解决此问题?

如何使用PlayWriter循环访问JSON对象

在Zig中解析JSON失败

使用快速json库编写json可以消除所有缩进

将JSON数组组织到菜单中

nlohmann json:为什么我会得到一个解析错误?

go 语言中的 JSON 到 XML

Delphi 11.3无法从变体创建/添加JSON

使用 JQ 从文件中删除重复的 JSON 块

Swift:如何从字典中删除空值?

在 Bash 中访问 JSON 对象 - 关联数组/列表/另一个模型

使用 @ResponseBody 自定义 HttpMessageConverter 来做 Json 事情

使用 Spring 和 JsonTypeInfo 注释将 JSON 反序列化为多态对象模型

IE中Json响应下载(7~10)

如何安装 json gem - 无法构建 gem 原生扩展(mac 10.10)

JSON日期到Java日期?

Sequelize - 如何仅返回数据库结果的 JSON 对象?

使用适用于 Python 的 Google API - 我从哪里获取 client_secrets.json 文件?

JSON 格式的 Amazon S3 响应?