功能
每次写模型都很头大,懒得写,所以想直接复制json自动创建好实体 通过注解生成json_serializable实体类的帮助类,搭配json_serializable食用 功能不完善,满足基本需求而已
编写如下代码:
import 'package:json_generator_helper/annotations/json_source.dart';
@JsonSource('{"name":[[]
,[]
,[]
],"level":99,"sex":"male","job":"programmer","obj":{"a":"1","b":false,"zxc":{"name":"zxc","asd":13},{"mo":"xx"}
},"child":"123","e452"
,"testChild":{"no":1},{"no":2},{"no":3}
}')
class UserInfo{}
自动生成类,剩下的交给json_serializable @JsonSerializable() class UserInfoModel { ... }
使用方法
添加依赖 dependencies: ... json_generator_helper: json_serializable: dev_dependencies: ... build_runner:
执行命令 flutter packages pub run build_runner build --delete-conflicting-outputs