【发布时间】:2023-03-25 13:34:01
【问题描述】:
我正在尝试从 api 获取一些数据,但它一直给我这个错误。其他数据模型也发生了同样的错误,但它可以自行运行,但这次没有。
我的数据模型:
class StoresModel {
final id;
final url;
final List<StoreModel> store;
StoresModel(this.id,this.url,this.store);
StoresModel.fromJson(Map<String, dynamic> json)
: id=json["id"]??"",
url=json["url"]??"",
store=(json["store"]as
List)?.map((i)=>StoreModel.fromJson(i))?.toList()
?? []; // Here's the error !!
}
class StoreModel {
final id;
final name;
StoreModel(this.id,this.name);
StoreModel.fromJson(Map<String, dynamic> json)
: id=json["id"]??"",
name=json["name"]??"";
}
API:
"stores": [
{
"id": 290375,
"url": "https://store.playstation.com/en-us/product/UP1004-CUSA00419_00-GTAVDIGITALDOWNL",
"store": {
"id": 3,
"name": "PlayStation Store",
"slug": "playstation-store",
"domain": "store.playstation.com",
"games_count": 7377,
"image_background":
"https://media.rawg.io/media/games/328/3283617cb7d75d67257fc58339188742.jpg"
}
},
【问题讨论】: