【发布时间】:2021-08-22 05:35:40
【问题描述】:
我有这个 Json。我想映射我的 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] type 'List' 不是 type 'String' 的子类型"
【问题讨论】:
-
展示你的模型
-
您是否得到了发生错误的行?因为
jsonArray[i]是dynamic类型,而您将其传递给fromJson函数。您应该将什么传递给fromJson?List还是需要String? -
我正在传递一个列表(产品)。我在 json 对象中有一个列表。
标签: json flutter dictionary