Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json本身的顶层级不是对象而是数组,解析报错 #28

Closed
kamike opened this issue Jun 4, 2020 · 4 comments
Closed

json本身的顶层级不是对象而是数组,解析报错 #28

kamike opened this issue Jun 4, 2020 · 4 comments

Comments

@kamike
Copy link

kamike commented Jun 4, 2020

image

[{"a":"xx","b":"bbb"},{"a":"xx","b":"bbbb"},{"a":"xx","b":"bbbbb"}]

image

dui对于这种整个json就是一个数组的,设置的没问题,解析报错
type 'String' is not a subtype of type 'int' of 'index'

我看了下,生成的代码jsonRes['json_list'],这里明显有问题,json_list这个key是不存在的,所以报错了

image

个人感觉对于这种类型,直接当做数组item的json来处理,额外再提供一下数组解析的方法就好了

@kamike
Copy link
Author

kamike commented Jun 5, 2020

如果要解析列表就要添加类似这样的一个方法
static List fromJsonList(String jsonStr) {
List listJson = json.decode(jsonStr);
List list = List();
for (var item in listJson) {
list.add(AddressInfoModel.fromJson(item));
}
return list;
}

@debuggerx01
Copy link
Owner

@kamike 是的,确实有问题,应该是之前某次更新影响产生的,有空我修复下,谢谢:-D

@debuggerx01
Copy link
Owner

Release 0.8

@kamike
Copy link
Author

kamike commented Jul 30, 2020

666

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants