flutter json_serializable
- 添加依赖库:
json_serializable: ^4.1.4
- json_serializable 自动生成工具:
https://caijinglong.github.io/json2dart/index.html
生成bean文件如下步骤:
步骤1-5如图
6、创建dart文件:my_bean.dart
7、黏贴复制内容
8、studio的Terminal 运行:flutter packages pub run build_runner build
9、自动生成文件:my_bean.g.dart
bean的使用:
//string 转 bean MyBean myBean = MyBean.fromJson(json.decode("……")); int result = myBean.result; int seq = myBean.seq; //bean 转 String print("myBean = "+json.encode(myBean));