如果您将从响应中获取数据,请确保您的数据转换为jsonDecode()
void main() {
var mapData = [
{
"id": 1072,
"title": "Magnetism Doit Chapter 1",
"gradeName": "Eight",
"subjectName": "Science",
"videoUrl": "hyRSO5RR3wo",
"status": false,
"createdDate": "2020-07-04 15:07:13",
"admin": false
},
{
"id": 1072,
"title": "Magnetism Doit Chapter 1",
"gradeName": "Eight",
"subjectName": "Science",
"videoUrl": "hyRSO5RR3wo",
"status": false,
"createdDate": "2020-07-04 15:07:13",
"admin": false
},
];
// json decode
// var data = jsonDecode(yourdata.body)
// print data list
mapData.map((element)=>print(ListItem.fromJson(element).title)).toList();
// store data list
List<ListItem> queryData = mapData.map((element)=>ListItem.fromJson(element)).toList();
print(queryData);
}
class ListItem{
int id;
String title;
String gradeName;
String subjectName;
String videoUrl;
bool status;
String createdDate;
bool admin;
ListItem(
{this.id,
this.title,
this.gradeName,
this.subjectName,
this.videoUrl,
this.status,
this.createdDate,
this.admin});
ListItem.fromJson(Map<String, dynamic> json) {
id = json['id'];
title = json['title'];
gradeName = json['gradeName'];
subjectName = json['subjectName'];
videoUrl = json['videoUrl'];
status = json['status'];
createdDate = json['createdDate'];
admin = json['admin'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['id'] = this.id;
data['title'] = this.title;
data['gradeName'] = this.gradeName;
data['subjectName'] = this.subjectName;
data['videoUrl'] = this.videoUrl;
data['status'] = this.status;
data['createdDate'] = this.createdDate;
data['admin'] = this.admin;
return data;
}
}