gpt4 book ai didi

json - 如何在Flutter中解析长度为1的JSON数组?

转载 作者:行者123 更新时间:2023-12-03 03:25:53 26 4
gpt4 key购买 nike

这是我的长度为JSON数组的代码,该数组返回长度为0的结果:

class profilInfo {
final List<information> result;
profilInfo._({ this.result});
factory profilInfo.fromJson(Map jsonMap) {
return new profilInfo._(
result : (jsonMap['result'] as List).map((i) =>
information.fromJson(i)).toList()
);
}
}

class information{
final String firstname;
final String country;
final String city;
final String about;
final String profilephoto;
information._({
this.firstname,this.country,this.about,this.city,this.profilephoto});
factory information.fromJson(Map jsonMap) {
return new information._(
firstname : jsonMap['first_name'],
country : jsonMap['country'],
city : (jsonMap['city']),
about : (jsonMap['about']),
profilephoto : (jsonMap['profile_photo']),
);
}
}

我有一个JSON文件:
{
"status": 200,
"result": [
{
"username": "mohammad",
"password": "202cb962ac59075b964b07152d234b70",
"create_date": "2019-08-13T08:53:24.997Z",
"modify_date": "2019-08-13T08:53:24.997Z",
"last_pay_date": null,
"first_name": "mohammad reza shabani",
"last_name": " ",
"country": "usa",
"city": "alai",
"phone": "09120564589",
"users_id": [],
"profile_photo": "",
"about": "",
"_id": "5d527a84abe6713aacc62453",
"__v": 0
}
]
}

我收到此错误:

[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: RangeError (index): Invalid value: Valid value range is empty: 0

最佳答案

我建议您要做的就是使用这个很棒的网站quik_types
为了创建将json对象转换为数据模型所需的类和函数,只需给他一个需要转换的json对象,其余的就交给他。它更快,输入更安全,因此可以节省很多不必要的工作和时间

关于json - 如何在Flutter中解析长度为1的JSON数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57476149/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com