我试图在 JsonOject 库的帮助下解析一些 JSON。我收到以下异常:
Exception: type 'List' is not a subtype of type 'Map' of 'value'.
我的代码:
class MyList extends JsonObject implements List {
MyList();
factory MyList.fromString(String jsonString) {
return new JsonObject.fromJsonString(jsonString, new MyList());
}
}
class MyResult extends JsonObject {
num Dis;
int Flag;
MyProduct Obj;
}
class MyProduct extends JsonObject {
int ID;
String Title;
}
我这样称呼它:
var testJson = """
[{"Dis":1111.1,"Flag":0,"Obj":{"ID":1,"Title":"Volvo 140"}},
{"Dis":2222.2,"Flag":0,"Obj":{"ID":2,"Title":"Volvo 240"}}]
""";
MyList list = new MyList.fromString(testJson);
//I want to be able to do something like this.
//print(list[0].Obj.Title);
我在这里做错了什么?