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 realSuperChapterId;

int selfVisible;

int shareDate;

String shareUser;

int superChapterId;

String superChapterName;

List tags;

String title;

int type;

int userId;

int visible;

int zan;

Person(

this.apkLink,

this.audit,

this.author,

this.canEdit,

this.chapterId,

this.chapterName,

this.collect,

this.courseId,

this.desc,

this.descMd,

this.envelopePic,

this.fresh,

this.host,

this.id,

this.link,

this.niceDate,

this.niceShareDate,

this.origin,

this.prefix,

this.projectLink,

this.publishTime,

this.realSuperChapterId,

this.selfVisible,

this.shareDate,

this.shareUser,

this.superChapterId,

this.superChapterName,

this.tags,

this.title,

this.type,

this.userId,

this.visible,

this.zan);

factory Person.fromJson(Map<String, dynamic> json) => _$PersonFromJson(json);

Map<String, dynamic> toJson() => _$PersonToJson(this);

}

@JsonSerializable()

class Tag {

String name;

String url;

Tag(this.name, this.url);

factory Tag.fromJson(Map<String, dynamic> json) => _$TagFromJson(json);

Map<String, dynamic> toJson() => _$TagToJson(this);

}

注意:

  • 添加part 'Article.g.dart';其中:Article是dart文件名,文件名+g.dart格式

  • 在每个需要序列化的类前面添加@JsonSerializable(),如类:ArticleArticleDataPersonTag

  • 每个类里面有:变量,构造函数,类名.fromJson() => _$类名FromJson(json)toJson() => _$类名ToJson(this)

3.3 生成序列化类.g.dart文件

执行如下指令

flutter pub run build_runner build

如无错误发生,生成Article.g.dart文件,Article.dart文件中_$类名FromJson(json)等不会再出现错误

四 序列化后类的应用


4.1 代码

late Future

futureArticle;

@override

void initState() {

super.initState();

futureArticle=_httpGet2();

}

Future

_httpGet2() async {

var httpClient = new HttpClient();

var uri = Uri(

scheme: ‘https’,

host: ‘www.wanandroid.com’,

path: ‘article/list/0/json’,

);

HttpClientRequest request = await httpClient.getUrl(uri);

HttpClientResponse response = await request.close();

String responseBody = await response.transform(utf8.decoder).join();

var jsonDecode = json.decode(responseBody);

var article =Article.fromJson(jsonDecode);

print(article);

return article;

}

//显示

FutureBuilder

(

future: futureArticle,

builder: (context, snapshot) {

if (snapshot.hasData) {

return ListView.separated(

itemCount: snapshot.data!.data.datas.length,

separatorBuilder: (context, index) {return Divider(height: 10, color: Colors.grey,);},

itemBuilder: (BuildContext context, int index) {

return Column(

children: [

Text(“${snapshot.data!.data.datas[index].author}”),

Text(“${snapshot.data!.data.datas[index].title}”),

Text(“${snapshot.data!.data.datas[index].niceShareDate}”)

],

);

},

);

} else if (snapshot.hasError) {

return Text(“${snapshot.error}”);
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则近万的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。

img

img

img

img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!

如果你觉得这些内容对你有帮助,可以扫码获取!!(备注:Android)

结语

看到这篇文章的人不知道有多少是和我一样的Android程序员。

35岁,这是我们这个行业普遍的失业高发阶段,这种情况下如果还不提升自己的技能,进阶发展,我想,很可能就是本行业的职业生涯的终点了。

我们要有危机意识,切莫等到一切都成定局时才开始追悔莫及。只要有规划的,有系统地学习,进阶提升自己并不难,给自己多充一点电,你才能走的更远。

千里之行始于足下。这是上小学时,那种一元钱一个的日记本上每一页下面都印刷有的一句话,当时只觉得这句话很短,后来渐渐长大才慢慢明白这句话的真正的含义。

有了学习的想法就赶快行动起来吧,不要被其他的事情牵绊住了前行的脚步。不要等到裁员时才开始担忧,不要等到面试前一晚才开始紧张,不要等到35岁甚至更晚才开始想起来要学习要进阶。

给大家一份系统的Android学习进阶资料,希望这份资料可以给大家提供帮助。

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!

个的日记本上每一页下面都印刷有的一句话,当时只觉得这句话很短,后来渐渐长大才慢慢明白这句话的真正的含义。

有了学习的想法就赶快行动起来吧,不要被其他的事情牵绊住了前行的脚步。不要等到裁员时才开始担忧,不要等到面试前一晚才开始紧张,不要等到35岁甚至更晚才开始想起来要学习要进阶。

给大家一份系统的Android学习进阶资料,希望这份资料可以给大家提供帮助。
[外链图片转存中…(img-ZYgwq4a8-1712760265062)]

《互联网大厂面试真题解析、进阶开发核心学习笔记、全套讲解视频、实战项目源码讲义》点击传送门即可获取!

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐