【问题标题】:Error 'A value of type 'dynamic' can't be assigned to a variable of type 'String'.'错误“无法将“动态”类型的值分配给“字符串”类型的变量。
【发布时间】:2021-07-22 20:45:17
【问题描述】:

“动态”类型的值不能分配给“地图”类型的变量。 尝试更改变量的类型,或将右侧类型转换为 'Map'。

// Get Channel
var response = await http.get(uri, headers: headers);
if (response.statusCode == 200) {
  Map<String, dynamic> data = json.decode(response.body)['items'][0] ;
  Channel channel = Channel.fromMap(data);

【问题讨论】:

    标签: list flutter dart


    【解决方案1】:

    json.decode(response.body) 返回 Map 类型的数据。

    如果您的 response.body['items'][0] 也是 Map,则应将其转换为 json.decode(response.body)['items'][0] as Map&lt;String, dynamic&gt;

    【讨论】:

      猜你喜欢
      • 2019-07-29
      • 1970-01-01
      • 2020-02-01
      • 2020-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-22
      • 1970-01-01
      相关资源
      最近更新 更多