Skip to content

Commit be0789b

Browse files
committed
修复issue#28,当顶层级为数组时解析错误;
移除new关键字; some fix; 版本号更新为0.8
1 parent d02a760 commit be0789b

12 files changed

+319
-189
lines changed

Test/EmptyResp.dart

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import 'dart:convert' show json;
22

33
class EmptyResp {
4-
54
Qwe qwe;
65

76
EmptyResp.fromParams({this.qwe});
87

9-
factory EmptyResp(jsonStr) => jsonStr == null ? null : jsonStr is String ? new EmptyResp.fromJson(json.decode(jsonStr)) : new EmptyResp.fromJson(jsonStr);
8+
factory EmptyResp(jsonStr) => jsonStr == null
9+
? null
10+
: jsonStr is String
11+
? EmptyResp.fromJson(json.decode(jsonStr))
12+
: EmptyResp.fromJson(jsonStr);
1013

1114
EmptyResp.fromJson(jsonRes) {
12-
qwe = jsonRes['qwe'] == null ? null : new Qwe.fromJson(jsonRes['qwe']);
15+
qwe = jsonRes['qwe'] == null ? null : Qwe.fromJson(jsonRes['qwe']);
1316
}
1417

1518
@override
@@ -19,7 +22,6 @@ class EmptyResp {
1922
}
2023

2124
class Qwe {
22-
2325
List<dynamic> asd;
2426
List<Object> qaz;
2527
List<dynamic> zxc;
@@ -29,26 +31,25 @@ class Qwe {
2931
Qwe.fromJson(jsonRes) {
3032
asd = jsonRes['asd'] == null ? null : [];
3133

32-
for (var asdItem in asd == null ? [] : jsonRes['asd']){
33-
asd.add(asdItem);
34+
for (var asdItem in asd == null ? [] : jsonRes['asd']) {
35+
asd.add(asdItem);
3436
}
3537

3638
qaz = jsonRes['qaz'] == null ? null : [];
3739

38-
for (var qazItem in qaz == null ? [] : jsonRes['qaz']){
39-
qaz.add(qazItem);
40+
for (var qazItem in qaz == null ? [] : jsonRes['qaz']) {
41+
qaz.add(qazItem);
4042
}
4143

4244
zxc = jsonRes['zxc'] == null ? null : [];
4345

44-
for (var zxcItem in zxc == null ? [] : jsonRes['zxc']){
45-
zxc.add(zxcItem);
46+
for (var zxcItem in zxc == null ? [] : jsonRes['zxc']) {
47+
zxc.add(zxcItem);
4648
}
4749
}
4850

4951
@override
5052
String toString() {
51-
return '{"asd": $asd,"qaz": $qaz,"zxc": $zxc}';
53+
return '{"asd": $asd, "qaz": $qaz, "zxc": $zxc}';
5254
}
5355
}
54-

Test/IgnoreMapResp.dart

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import 'dart:convert' show json;
22

33
class IgnoreMapResp {
4-
54
Data data;
65

76
IgnoreMapResp.fromParams({this.data});
87

9-
factory IgnoreMapResp(jsonStr) => jsonStr == null ? null : jsonStr is String ? new IgnoreMapResp.fromJson(json.decode(jsonStr)) : new IgnoreMapResp.fromJson(jsonStr);
8+
factory IgnoreMapResp(jsonStr) => jsonStr == null
9+
? null
10+
: jsonStr is String
11+
? IgnoreMapResp.fromJson(json.decode(jsonStr))
12+
: IgnoreMapResp.fromJson(jsonStr);
1013

1114
IgnoreMapResp.fromJson(jsonRes) {
12-
data = jsonRes['data'] == null ? null : new Data.fromJson(jsonRes['data']);
15+
data = jsonRes['data'] == null ? null : Data.fromJson(jsonRes['data']);
1316
}
1417

1518
@override
@@ -19,7 +22,6 @@ class IgnoreMapResp {
1922
}
2023

2124
class Data {
22-
2325
int wc;
2426
String author;
2527
String content;
@@ -28,7 +30,14 @@ class Data {
2830
Map<String, dynamic> date;
2931
Extra extra;
3032

31-
Data.fromParams({this.wc, this.author, this.content, this.digest, this.title, this.date, this.extra});
33+
Data.fromParams(
34+
{this.wc,
35+
this.author,
36+
this.content,
37+
this.digest,
38+
this.title,
39+
this.date,
40+
this.extra});
3241

3342
Data.fromJson(jsonRes) {
3443
wc = jsonRes['wc'];
@@ -37,17 +46,16 @@ class Data {
3746
digest = jsonRes['digest'];
3847
title = jsonRes['title'];
3948
date = jsonRes['date'];
40-
extra = jsonRes['extra'] == null ? null : new Extra.fromJson(jsonRes['extra']);
49+
extra = jsonRes['extra'] == null ? null : Extra.fromJson(jsonRes['extra']);
4150
}
4251

4352
@override
4453
String toString() {
45-
return '{"wc": $wc,"author": ${author != null?'${json.encode(author)}':'null'},"content": ${content != null?'${json.encode(content)}':'null'},"digest": ${digest != null?'${json.encode(digest)}':'null'},"title": ${title != null?'${json.encode(title)}':'null'},"date": ${date != null?'${json.encode(date)}':'null'},"extra": $extra}';
54+
return '{"wc": $wc, "author": ${author != null ? '${json.encode(author)}' : 'null'}, "content": ${content != null ? '${json.encode(content)}' : 'null'}, "digest": ${digest != null ? '${json.encode(digest)}' : 'null'}, "title": ${title != null ? '${json.encode(title)}' : 'null'}, "date": ${date != null ? '${json.encode(date)}' : 'null'}, "extra": $extra}';
4655
}
4756
}
4857

4958
class Extra {
50-
5159
int a;
5260
int b;
5361
int c;
@@ -62,7 +70,6 @@ class Extra {
6270

6371
@override
6472
String toString() {
65-
return '{"a": $a,"b": $b,"c": $c}';
73+
return '{"a": $a, "b": $b, "c": $c}';
6674
}
6775
}
68-

Test/ListTopResp.dart

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import 'dart:convert' show json;
2+
3+
class ListTopResp {
4+
List<Resp> list;
5+
6+
ListTopResp.fromParams({this.list});
7+
8+
factory ListTopResp(jsonStr) => jsonStr == null
9+
? null
10+
: jsonStr is String
11+
? ListTopResp.fromJson(json.decode(jsonStr))
12+
: ListTopResp.fromJson(jsonStr);
13+
14+
ListTopResp.fromJson(jsonRes) {
15+
list = jsonRes == null ? null : [];
16+
17+
for (var listItem in list == null ? [] : jsonRes) {
18+
list.add(listItem == null ? null : Resp.fromJson(listItem));
19+
}
20+
}
21+
22+
@override
23+
String toString() {
24+
return '{"json_list": $list}';
25+
}
26+
}
27+
28+
class Resp {
29+
String a;
30+
String b;
31+
32+
Resp.fromParams({this.a, this.b});
33+
34+
Resp.fromJson(jsonRes) {
35+
a = jsonRes['a'];
36+
b = jsonRes['b'];
37+
}
38+
39+
@override
40+
String toString() {
41+
return '{"a": ${a != null ? '${json.encode(a)}' : 'null'}, "b": ${b != null ? '${json.encode(b)}' : 'null'}}';
42+
}
43+
}

Test/ListTopTest.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
"a": "xx",
4+
"b": "bbb"
5+
},
6+
{
7+
"a": "xx",
8+
"b": "bbbb"
9+
},
10+
{
11+
"a": "xx",
12+
"b": "bbbbb"
13+
}
14+
]

Test/ListsResp.dart

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,62 @@
11
import 'dart:convert' show json;
22

33
class ListsResp {
4-
54
List<List<List<int>>> asd;
65
List<int> qaz;
76
List<List<List<Zxc>>> qwe;
87

98
ListsResp.fromParams({this.asd, this.qaz, this.qwe});
109

11-
factory ListsResp(jsonStr) => jsonStr == null ? null : jsonStr is String ? new ListsResp.fromJson(json.decode(jsonStr)) : new ListsResp.fromJson(jsonStr);
10+
factory ListsResp(jsonStr) => jsonStr == null
11+
? null
12+
: jsonStr is String
13+
? ListsResp.fromJson(json.decode(jsonStr))
14+
: ListsResp.fromJson(jsonStr);
1215

1316
ListsResp.fromJson(jsonRes) {
1417
asd = jsonRes['asd'] == null ? null : [];
1518

16-
for (var asdItem in asd == null ? [] : jsonRes['asd']){
17-
List<List<int>> asdChild = asdItem == null ? null : [];
18-
for (var asdItemItem in asdChild == null ? [] : asdItem){
19-
List<int> asdChildChild = asdItemItem == null ? null : [];
20-
for (var asdItemItemItem in asdChildChild == null ? [] : asdItemItem){
21-
asdChildChild.add(asdItemItemItem);
22-
}
23-
asdChild.add(asdChildChild);
24-
}
19+
for (var asdItem in asd == null ? [] : jsonRes['asd']) {
20+
List<List<int>> asdChild = asdItem == null ? null : [];
21+
for (var asdItemItem in asdChild == null ? [] : asdItem) {
22+
List<int> asdChildChild = asdItemItem == null ? null : [];
23+
for (var asdItemItemItem in asdChildChild == null ? [] : asdItemItem) {
24+
asdChildChild.add(asdItemItemItem);
25+
}
26+
asdChild.add(asdChildChild);
27+
}
2528
asd.add(asdChild);
2629
}
2730

2831
qaz = jsonRes['qaz'] == null ? null : [];
2932

30-
for (var qazItem in qaz == null ? [] : jsonRes['qaz']){
31-
qaz.add(qazItem);
33+
for (var qazItem in qaz == null ? [] : jsonRes['qaz']) {
34+
qaz.add(qazItem);
3235
}
3336

3437
qwe = jsonRes['qwe'] == null ? null : [];
3538

36-
for (var qweItem in qwe == null ? [] : jsonRes['qwe']){
37-
List<List<Zxc>> qweChild = qweItem == null ? null : [];
38-
for (var qweItemItem in qweChild == null ? [] : qweItem){
39-
List<Zxc> qweChildChild = qweItemItem == null ? null : [];
40-
for (var qweItemItemItem in qweChildChild == null ? [] : qweItemItem){
41-
qweChildChild.add(qweItemItemItem == null ? null : new Zxc.fromJson(qweItemItemItem));
42-
}
43-
qweChild.add(qweChildChild);
44-
}
39+
for (var qweItem in qwe == null ? [] : jsonRes['qwe']) {
40+
List<List<Zxc>> qweChild = qweItem == null ? null : [];
41+
for (var qweItemItem in qweChild == null ? [] : qweItem) {
42+
List<Zxc> qweChildChild = qweItemItem == null ? null : [];
43+
for (var qweItemItemItem in qweChildChild == null ? [] : qweItemItem) {
44+
qweChildChild.add(
45+
qweItemItemItem == null ? null : Zxc.fromJson(qweItemItemItem));
46+
}
47+
qweChild.add(qweChildChild);
48+
}
4549
qwe.add(qweChild);
4650
}
4751
}
4852

4953
@override
5054
String toString() {
51-
return '{"asd": $asd,"qaz": $qaz,"qwe": $qwe}';
55+
return '{"asd": $asd, "qaz": $qaz, "qwe": $qwe}';
5256
}
5357
}
5458

5559
class Zxc {
56-
5760
int zxc;
5861

5962
Zxc.fromParams({this.zxc});
@@ -67,4 +70,3 @@ class Zxc {
6770
return '{"zxc": $zxc}';
6871
}
6972
}
70-

0 commit comments

Comments
 (0)