繁体   English   中英

flutter 上的错误:键入“列表”<dynamic> ' 不是类型 'String' 的子类型</dynamic>

[英]Error on flutter : type 'List<dynamic>' is not a subtype of type 'String'

我有这个 Json。 我想 map 我的 json 数据。 但我得到一些错误。

{
"Id": 0,
"Product_Id": 0,
"Quantity": 0,
"User_Id": "a49a10d2-fc3f-477a-b087-5b0d07545964",
"Active": false,
"CartProducts": null,
"Products": [
    {
        "Id": 116,
        "Shop_Id": 1,
        "Offer": 0.0,
        "Quantity": 1,
        "Price": 100.0,
        "Category_Id": 0,
        "Description": null,
        "Name": "Lacoste Product",
        "Active": false,
        "Size": "small",
        "Color": "black",
        "Is_External_Product": true,
        "External_Link": "https://www.lacoste.com.tr/urun/kadin-kirmizi-polo-pf0504-007-4/",
        "Currency": null,
        "ProductImages": null
    }
]
} 

我在这里解码 Json

if(jsonObject['Products']!=null){
  productItems = ProductItem.getListFromJson(jsonObject['Products']);
}

static List<ProductItem> getListFromJson(List<dynamic> jsonArray) {
log("getListFromJson");
List<ProductItem> list = [];
for (int i = 0; i < jsonArray.length; i++) {
  list.add(ProductItem.fromJson(jsonArray[i]));
}
return list;
 }

但我得到这个错误。 “[log] 类型 'List' 不是类型 'String' 的子类型”

您正在尝试将 String 类型的值分配给 product items 数组。 您的响应之一可能是返回一个字符串,而您期望的是一个数组。 请检查响应。

这是一个 JSON 解析问题,它可能与作为列表或字符串的“产品”没有直接关系。

因此,为了更好地诊断此错误或将来的其他错误,您可能需要启用 dart 调试器,同时检查“未捕获的异常”选项,这将引导您解决类型转换问题。

为未捕获的异常启用 dart 调试器

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM