gpt4 book ai didi

flutter - 将对象转换为可编码对象失败 : Instance of '_CompactLinkedHashSet>'

转载 作者:行者123 更新时间:2023-12-03 04:37:22 24 4
gpt4 key购买 nike

当我尝试调用下面的函数时, flutter 返回此错误:Converting object to an encodable object failed: Instance of '_CompactLinkedHashSet '
代码:

 Future<void> signupVisitor() async {
final _baseUrlToinu = 'https://api.toinu.com.br/api/v1/auth/signup';

final response = await http.post(_baseUrlToinu,
body: json.encode({
"nameCountry": "Brazil",
"states": [
{
"initials": "MG",
"cities": {
["city 1", "city 2", "city 3"]
}
}
]
}));

final responseBody = json.decode(response.body);
print(responseBody);

}

最佳答案

尝试修复“城市”的值(value)。
我认为这个 {['city1', 'citi2'...]} 代码是错误的。
'cities' 值是一个对象,因为您使用了 '{}' 但没有键。
如果您想将“城市”值作为数组 [],则需要删除“{}”。

json.encode({
"nameCountry": "Brazil",
"states": [
{
"initials": "MG",
"cities":
["city 1", "city 2", "city 3"]

}
]
})

关于flutter - 将对象转换为可编码对象失败 : Instance of '_CompactLinkedHashSet<List<String>>' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63877099/

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