【问题标题】:Expected a value of type 'List<dynamic>', but got one of type '_JsonMap'期望类型为 \'List<dynamic>\' 的值,但得到类型为 \'_JsonMap\' 的值
【发布时间】:2023-01-02 19:05:16
【问题描述】:

当我尝试解码 json 时出现此错误 Expected a value of type 'List&lt;dynamic&gt;', but got one of type '_JsonMap'

这是我试过的

`

Future getPayment() async {
  final response = await http
      .get(Uri.parse('https://msq5vv563d.execute-api.ap-south-1.amazonaws.com/stage1/api/dock_pay_details/get_dock_pay_details_by_id/${widget.docketData['general_id']}'),
    headers: {
      "Content-Type": "application/json",
      'Authorization': 'Bearer $authToken'
    },
  );
  if (response.statusCode == 200) {
    setState(() {
      paymentList=jsonDecode(response.body);
    });
  } else {
    dev.log("++++++++++Status Code +++++++++++++++");
    dev.log(response.statusCode.toString());
  }
}

`

【问题讨论】:

  • 请分享您的回复 Json 回复正文
  • 你能分享你的响应主体和 paymentList 对象的类吗?

标签: flutter


【解决方案1】:

你做的作业设置状态paymentList=jsonDecode(response.body);表示response.body是地图并且您将其分配给 paymentList 类型列表.

【讨论】:

    猜你喜欢
    • 2021-11-04
    • 2021-07-13
    • 2021-05-29
    • 1970-01-01
    • 2021-11-03
    • 2021-12-17
    • 2021-07-29
    • 2022-10-14
    • 2021-11-15
    相关资源
    最近更新 更多