[英]get data from array in flutter
thanks for checking out my question i have the following json data感谢您查看我的问题,我有以下 json 数据
array(568) {
[0]=>
array(11) {
["ID"]=>
string(6) "000001"
["Portrait"]=>
string(12) "BaseGoku.png"
["Name"]=>
string(42) "[The Saiyan who grew up on Earth] Son Goku"
["Series"]=>
string(11) "Dragon Ball"
["MaxRarity"]=>
string(6) "6 Star"
["Type"]=>
string(4) "Blue"
["Class"]=>
string(4) "Tank"
["Era"]=>
string(4) "1980"
["ReleaseDate"]=>
string(10) "2018-03-28"
["Farmable"]=>
string(1) "0"
["Method"]=>
string(17) "Trade Medal Store"
}
[1]=>
array(11) {
["ID"]=>
string(6) "000003"
["Portrait"]=>
string(8) "Goku.png"
["Name"]=>
string(8) "Son Goku"
["Series"]=>
string(11) "Dragon Ball"
["MaxRarity"]=>
string(6) "6 Star"
["Type"]=>
string(6) "Yellow"
["Class"]=>
string(3) "DPS"
["Era"]=>
string(4) "1980"
["ReleaseDate"]=>
string(10) "2018-03-28"
["Farmable"]=>
string(1) "0"
["Method"]=>
string(14) "Standard Gacha"
} etc
i have been tring to decode this and pull the data using a future我一直在尝试解码它并使用未来提取数据
Future<Users> fetchInfo() async {
final response = await http.get(jsonplaceholder);
final jsonresponse = json.decode(response.body);
return Users.fromJson(jsonresponse[8]);
}
but i keep getting the error "Error FormatException: Unexpected character(at character 1) array(568) not to sure what im doing wrong as i am new to flutter any help would be appreciated thanks但我不断收到错误消息“错误格式异常:意外字符(字符 1)数组(568)不确定我做错了什么,因为我是新手,不胜感激,感谢
heres the users model这是用户模型
class Users {
final int userID;
final String name;
final String portrait;
final String series;
Users({this.name, this.userID, this.portrait, this.series});
factory Users.fromJson(Map<String, dynamic> usersjson)=> Users(
name: usersjson["name"],
);
}
First of all are you sure this is the json data you're getting cause it should be like首先,你确定这是你得到的 json 数据,因为它应该像
[
{
"ID": "000001"
"Name": "[The Saiyan who grew up on Earth] Son Goku",
"Portrait": "BaseGoku.png",
"Series": "Dragon Ball",
"MaxRarity": "6 start",
"Type": "Blue",
"Class": "Tank",
"Era": "1980",
"Release Date": "2018-03-28",
"Farmable": "0",
"Method": "Trade Medal Store"
}
]
Flutter expects Map type for json.decode
. Flutter 期望json.decode
为 Map 类型。 If it's a public api can you please post it here.如果它是一个公共api,你可以在这里发布它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.