在颤动中发布数组变量
Posting array variable in flutter
我想要 post 数组变量,但出现以下错误:
ConvException has occurred. JsonUnsupportedObjectError (erting object to an encodable object failed: _LinkedHashMap len:15)
我的class:
class Answer {
int facility;
String assesment_category;
Map<int, dynamic> input = {};
Answer(
{this.facility,
this.assesment_category,
this.input});
factory Answer.fromJson(Map<String, dynamic> map) {
return Answer(
facility: map["facility"],
assesment_category: map["assesment_category"],
input: map["input"]);
}
Map<String, dynamic> toJson() {
return {
"facility": facility,
"assesment_category": assesment_category,
"input": input
};
}
我的 post 结果:
"facility":1,
"assesment_category":"internal",
"input":{
0:4,
1:5,
}
如果我不使用数组变量,它就可以工作,所以我认为有一种方法可以 post if 作为数组
非常感谢。
我错误的用Map初始化了变量,正确的数组初始化是
List<int> input = [];
我想要 post 数组变量,但出现以下错误:
ConvException has occurred. JsonUnsupportedObjectError (erting object to an encodable object failed: _LinkedHashMap len:15)
我的class:
class Answer {
int facility;
String assesment_category;
Map<int, dynamic> input = {};
Answer(
{this.facility,
this.assesment_category,
this.input});
factory Answer.fromJson(Map<String, dynamic> map) {
return Answer(
facility: map["facility"],
assesment_category: map["assesment_category"],
input: map["input"]);
}
Map<String, dynamic> toJson() {
return {
"facility": facility,
"assesment_category": assesment_category,
"input": input
};
}
我的 post 结果:
"facility":1,
"assesment_category":"internal",
"input":{
0:4,
1:5,
}
如果我不使用数组变量,它就可以工作,所以我认为有一种方法可以 post if 作为数组
非常感谢。
我错误的用Map初始化了变量,正确的数组初始化是
List<int> input = [];