问题
this question is already asked in here (convert JSON String to the list object in flutter) by someone else.. but right now.. I don't get the answer yet.. so is there a way to call List<LoginRespon>
... I have converted from json respond using https://app.quicktype.io/ and here is the code
import 'dart:convert';
LoginRespon loginResponFromJson(String str) => LoginRespon.fromJson(json.decode(str));
String loginResponToJson(LoginRespon data) => json.encode(data.toJson());
class LoginRespon {
String status;
Data data;
LoginRespon({
this.status,
this.data,
});
factory LoginRespon.fromJson(Map<String, dynamic> json) => LoginRespon(
status: json["status"],
data: Data.fromJson(json["data"]),
);
Map<String, dynamic> toJson() => {
"status": status,
"data": data.toJson(),
};
}
class Data {
String resource;
String unit;
Data({
this.resource,
this.unit,
});
factory Data.fromJson(Map<String, dynamic> json) => Data(
resource: json["resource"],
unit: json["unit"],
);
Map<String, dynamic> toJson() => {
"resource": resource,
"unit": unit,
};
}
and here is the original json data
{
"status":200,
"data":{
"resource":"abc",
"unit":"a"
}
}
来源:https://stackoverflow.com/questions/61554156/how-to-create-a-list-from-json-string-in-flutter