我对Flutter还是很陌生,希望能对您有所帮助,我正在尝试映射一个JSON文件,如此处所示,但是在映射某些值时是动态的,例如“ Example 1”就是我的方式映射我的示例列表,但名称并不总是示例1,如何映射它?
JSON文件
{
"message": {
"2018/19": {
"Example 1": [
{
"name": "Test"
"value": "1.0"
}
]
}
}
}
飞镖文件
class Message {
List<Year> year;
Message(List<Year> year) {
this.year = year;
}
Message.fromJson(Map json)
: year = json['message'];
}
class Year {
List<Examples> example;
Year(List<Examples> example) {
this.example = example;
}
Year.fromJson(Map json)
: Example = json['example']; // It is example but it could be any name
}
class Examples {
String name;
Double value;
Examples(String name, Double value) {
this.name = name;
this.value = value;
}
Year.fromJson(Map json)
: name = json['name'],
value = json['value'],
}