debuggerx01 / jsonformat4flutter Goto Github PK
View Code? Open in Web Editor NEW受zzz40500/GsonFormat启发,将JSONObject格式的String解析成dart语言的实体类
受zzz40500/GsonFormat启发,将JSONObject格式的String解析成dart语言的实体类
你好,感谢开源贡献。
我在使用过程中发现:首次生成bean没有问题,当程序窗口没有关闭的情况下再次复制另一个json格式化之后,点击红色区域命名的时候程序会卡死直至崩溃,望查验。
NewsListBean.fromJson(jsonRes) {
if (jsonRes['count'] != null) {
count = jsonRes['count'];
}
if (jsonRes['hasMore'] != null) {
hasMore = jsonRes['hasMore'];
}
if (jsonRes['uri'] != null) {
uri = jsonRes['uri'];
}
}
类似这样的json,现在无法直接处理
json文件
map.txt
未能打开文稿“Formatter_mac”。文本编码“Unicode (UTF-8)”不适用。
Mac下载的是一个文件没有拓展名要用什么打开?
怎么不把这个搞成 IDEA plugin 呢,这样不就方便很多了嘛。
按照操作步骤执行生成后,只有“import 'dart:convert' show json;”这一句
发生错误在通过以下:
{
"x":{
"q":[],
"t":[],
"e":[{}]
}
}
看到tostring里面大佬做了很多处理,但是发现还有问题,比如string是“”的时候。。tostring的字符串没法正常转换json。
建议生成类似这样的
Map<String, dynamic> toJson() => {
'id': id,
};
@override
String toString() {
// TODO: implement toString
return json.encode(toJson());
}
谢谢
发现生成的class中只有一个带参的构造函数,如果我不直接传jsonStr进去,而是想初始化一个空的class。给class一个默认构造函数,给转换构造函数加一个命名是不是更好?
Json
{ "name": "BeJson", "email": "http://www.bejson.com", "list": [ "Google", "baidu", "facebook" ] }
Class,嵌套class以此类推
class UserModel {
String email;
String name;
List<String> list;
UserModel(){
list = [];
}
UserModel.byJson(jsonStr) {
var jsonRes = json.decode(jsonStr);
email = jsonRes['email'];
name = jsonRes['name'];
list = [];
for (var listItem in jsonRes['list']){
list.add(listItem);
}
}
初学dart,语法还不太熟,请见谅
RT
0.7mac版不会生成代码
刚升了 Flutter 1.20,并尝试迁移代码到 non-nullable,突然发现用这个工具生成的 json 代码全部都报错了。
result数据为{"result":[{"name":"测试分类1","id":"1"},{"name":"测试分类3","id":"3"},{"name":"测试分类","id":"5"}]}
for (var resultItem in jsonRes['result']){
result.add(new ListBean.fromJson(resultItem));
}
无法转换 会 'String' is not a subtype of type 'int' of 'index'
判断string还不够的,后面还要判断是否是字典类型,要不然穿个别的类型也不行
在mac系统下
复制左部生成的bean文件的文本
到idea中会变成65279开头
在idea的开发环境下 会造成报错
大佬能否支持 下面2个功能
1.支持字段驼峰
2.解析List的时候是否可以读取多个数据(默认是解析的是第一个,但是可能第一个数据字段不全)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.