转换后
3.4 将Json彻底转换为数据类
数据类
class Article {
int errorCode;
String errorMsg;
ArticleData data;
Article(this.errorCode, this.errorMsg, this.data);
Article.formJson(Map<String, dynamic> json) {
Article(
errorCode= json[‘errorCode’],
errorMsg = json[‘errorMsg’],
data = ArticleData.fromJson(json[‘data’])
);
}
}
class ArticleData {
int curPage;
int offset;
bool over;
int pageCount;
int size;
int total;
List datas;
ArticleData(this.curPage, this.offset, this.over, this.pageCount, this.size,
this.total, this.datas);
ArticleData.fromJson(Map<String, dynamic> json) {
var personList = List();
for (Map<String, dynamic> map in json[‘datas’]) {
personList.add(Person.fromJson(map));
}
ArticleData(
curPage = json[‘curPage’],
offset = json[‘curPage’],
over = json[‘over’],
pageCount = json[‘pageCount’],
size = json[‘size’],
total = json[‘total’],
datas = personList);
}
}
class Person {
String apkLink;
int audit;
String author;
bool canEdit;
int chapterId;
String chapterName;
bool collect;
int courseId;
String desc;
String descMd;
String envelopePic;
bool fresh;
String host;
int id;
String link;
String niceDate;
String niceShareDate;
String origin;
String prefix;
String projectLink;
int publishTime;
int rea