Skip to content

Commit f82afb2

Browse files
committed
修改丢人的文件名拼写错误;加入测试用例
1 parent 0386a16 commit f82afb2

12 files changed

Lines changed: 3601 additions & 3 deletions

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Created by .ignore support plugin (hsz.mobi)
22

33
.idea
4-
*.pyc
4+
*.pyc
5+
6+
Test/.dart_tool
7+
Test/.idea
8+
Test/.packages

Test/EmptyResp.dart

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import 'dart:convert' show json;
2+
3+
4+
class EmptyResp {
5+
6+
Qwe qwe;
7+
8+
9+
EmptyResp.fromParams({this.qwe});
10+
11+
factory EmptyResp(jsonStr) => jsonStr is String ? EmptyResp.fromJson(json.decode(jsonStr)) : EmptyResp.fromJson(jsonStr);
12+
13+
EmptyResp.fromJson(jsonRes) {
14+
qwe = new Qwe.fromJson(jsonRes['qwe']);
15+
16+
}
17+
18+
@override
19+
String toString() {
20+
return '{"qwe": $qwe}';
21+
}
22+
}
23+
24+
25+
26+
class Qwe {
27+
28+
List<dynamic> asd;
29+
List<Object> qaz;
30+
List<dynamic> zxc;
31+
32+
33+
Qwe.fromParams({this.asd, this.qaz, this.zxc});
34+
35+
Qwe.fromJson(jsonRes) {
36+
asd = jsonRes['asd'];
37+
qaz = jsonRes['qaz'];
38+
zxc = jsonRes['zxc'];
39+
40+
}
41+
42+
@override
43+
String toString() {
44+
return '{"asd": $asd,"qaz": $qaz,"zxc": $zxc}';
45+
}
46+
}
47+

Test/EmptyTest.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"qwe":{
3+
"asd":[],
4+
"zxc":[],
5+
"qaz":[{}]
6+
}
7+
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ class RegionResp {
1111

1212
RegionResp.fromParams({this.code, this.ttl, this.message, this.data});
1313

14-
factory RegionResp(jsonStr) => RegionResp.fromJson(json.decode(jsonStr));
14+
factory RegionResp(jsonStr) => jsonStr is String ? RegionResp.fromJson(json.decode(jsonStr)) : RegionResp.fromJson(jsonStr);
1515

1616
RegionResp.fromJson(jsonRes) {
1717
code = jsonRes['code'];
1818
ttl = jsonRes['ttl'];
1919
message = jsonRes['message'];
2020
data = new Data.fromJson(jsonRes['data']);
21-
2221
}
2322

2423
@override
File renamed without changes.

Test/WanResp.dart

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import 'dart:convert' show json;
2+
3+
4+
class WanResp {
5+
6+
int errorCode;
7+
String errorMsg;
8+
List<Data> data;
9+
10+
11+
WanResp.fromParams({this.errorCode, this.errorMsg, this.data});
12+
13+
factory WanResp(jsonStr) => jsonStr is String ? WanResp.fromJson(json.decode(jsonStr)) : WanResp.fromJson(jsonStr);
14+
15+
WanResp.fromJson(jsonRes) {
16+
errorCode = jsonRes['errorCode'];
17+
errorMsg = jsonRes['errorMsg'];
18+
data = [];
19+
20+
for (var dataItem in jsonRes['data']){
21+
22+
data.add(new Data.fromJson(dataItem));
23+
}
24+
25+
26+
}
27+
28+
@override
29+
String toString() {
30+
return '{"errorCode": $errorCode,"errorMsg": ${errorMsg != null?'${json.encode(errorMsg)}':'null'},"data": $data}';
31+
}
32+
}
33+
34+
35+
36+
class Data {
37+
38+
int courseId;
39+
int id;
40+
int order;
41+
int parentChapterId;
42+
int visible;
43+
String name;
44+
List<Children> children;
45+
46+
47+
Data.fromParams({this.courseId, this.id, this.order, this.parentChapterId, this.visible, this.name, this.children});
48+
49+
Data.fromJson(jsonRes) {
50+
courseId = jsonRes['courseId'];
51+
id = jsonRes['id'];
52+
order = jsonRes['order'];
53+
parentChapterId = jsonRes['parentChapterId'];
54+
visible = jsonRes['visible'];
55+
name = jsonRes['name'];
56+
children = [];
57+
58+
for (var childrenItem in jsonRes['children']){
59+
60+
children.add(new Children.fromJson(childrenItem));
61+
}
62+
63+
64+
}
65+
66+
@override
67+
String toString() {
68+
return '{"courseId": $courseId,"id": $id,"order": $order,"parentChapterId": $parentChapterId,"visible": $visible,"name": ${name != null?'${json.encode(name)}':'null'},"children": $children}';
69+
}
70+
}
71+
72+
73+
74+
class Children {
75+
76+
int courseId;
77+
int id;
78+
int order;
79+
int parentChapterId;
80+
int visible;
81+
String name;
82+
List<dynamic> children;
83+
84+
85+
Children.fromParams({this.courseId, this.id, this.order, this.parentChapterId, this.visible, this.name, this.children});
86+
87+
Children.fromJson(jsonRes) {
88+
courseId = jsonRes['courseId'];
89+
id = jsonRes['id'];
90+
order = jsonRes['order'];
91+
parentChapterId = jsonRes['parentChapterId'];
92+
visible = jsonRes['visible'];
93+
name = jsonRes['name'];
94+
children = jsonRes['children'];
95+
96+
}
97+
98+
@override
99+
String toString() {
100+
return '{"courseId": $courseId,"id": $id,"order": $order,"parentChapterId": $parentChapterId,"visible": $visible,"name": ${name != null?'${json.encode(name)}':'null'},"children": $children}';
101+
}
102+
}
103+

0 commit comments

Comments
 (0)