![](/img/trans.png)
[英]Flutter Error: List<dynamic> is not a subtype of type Map<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 数组。 您的响应之一可能是返回一个字符串,而您期望的是一个数组。 请检查响应。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.