Flutter开发之——json序列化,android开发入门书籍推荐

dependencies:

json_annotation: ^4.0.1 #json_annotation版本

dev_dependencies:

build_runner: ^2.0.3 #build_runner版本

json_serializable: ^4.1.2 #json_serializable版本

三 根据json创建序列化类


3.1 接口文件

  • API:https://www.wanandroid.com/article/list/0/json

3.2 序列化类(Article.dart)

import ‘package:json_annotation/json_annotation.dart’;

part ‘Article.g.dart’;

@JsonSerializable()

class Article {

int errorCode;

String errorMsg;

ArticleData data;

Article(this.errorCode, this.errorMsg, this.data);

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

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

}

@JsonSerializable()

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

factory ArticleData.fromJson(Map<String, dynamic> json) =

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享

_$ArticleDataFromJson(json);

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

}

@JsonSerializable()

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

}

注意:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值