1import 'dart:convert';
2...
3json.encode(data); // JSON.encode(data) in Dart 1.x
4
1import 'dart:convert';
2
3main() {
4 String nestedObjText =
5 '{"title": "Dart Tutorial", "description": "Way to parse Json", "author": {"name": "bezkoder", "age": 30}}';
6
7 Tutorial tutorial = Tutorial.fromJson(jsonDecode(nestedObjText));
8
9 print(tutorial);
10
1class Autogenerated {
2 int userId;
3 int id;
4 String title;
5 String body;
6
7 Autogenerated({this.userId, this.id, this.title, this.body});
8
9 Autogenerated.fromJson(Map<String, dynamic> json) {
10 userId = json['userId'];
11 id = json['id'];
12 title = json['title'];
13 body = json['body'];
14 }
15
16 Map<String, dynamic> toJson() {
17 final Map<String, dynamic> data = new Map<String, dynamic>();
18 data['userId'] = this.userId;
19 data['id'] = this.id;
20 data['title'] = this.title;
21 data['body'] = this.body;
22 return data;
23 }
24}
25
1class Autogenerated {
2 int postId;
3 int id;
4 String name;
5 String email;
6 String body;
7
8 Autogenerated({this.postId, this.id, this.name, this.email, this.body});
9
10 Autogenerated.fromJson(Map<String, dynamic> json) {
11 postId = json['postId'];
12 id = json['id'];
13 name = json['name'];
14 email = json['email'];
15 body = json['body'];
16 }
17
18 Map<String, dynamic> toJson() {
19 final Map<String, dynamic> data = new Map<String, dynamic>();
20 data['postId'] = this.postId;
21 data['id'] = this.id;
22 data['name'] = this.name;
23 data['email'] = this.email;
24 data['body'] = this.body;
25 return data;
26 }
27}
28
1class posts {
2 int idPost;
3 String datePost;
4 String objectPost;
5 String contenuPost;
6 double latitude;
7 double longitude;
8 List<Null> fichiers;
9 Null domaine;
10 List<Null> partages;
11 Null user;
12 List<Null> commentaireCorpsMetiers;
13 Null post;
14 List<Null> sousPost;
15 List<Null> votes;
16 List<Null> likes;
17
18 posts(
19 {this.idPost,
20 this.datePost,
21 this.objectPost,
22 this.contenuPost,
23 this.latitude,
24 this.longitude,
25 this.fichiers,
26 this.domaine,
27 this.partages,
28 this.user,
29 this.commentaireCorpsMetiers,
30 this.post,
31 this.sousPost,
32 this.votes,
33 this.likes});
34
35 posts.fromJson(Map<String, dynamic> json) {
36 idPost = json['id_post'];
37 datePost = json['date_post'];
38 objectPost = json['object_post'];
39 contenuPost = json['contenu_post'];
40 latitude = json['latitude'];
41 longitude = json['longitude'];
42 if (json['fichiers'] != null) {
43 fichiers = new List<Null>();
44 json['fichiers'].forEach((v) {
45 fichiers.add(new Null.fromJson(v));
46 });
47 }
48 domaine = json['domaine'];
49 if (json['partages'] != null) {
50 partages = new List<Null>();
51 json['partages'].forEach((v) {
52 partages.add(new Null.fromJson(v));
53 });
54 }
55 user = json['user'];
56 if (json['commentaire_corpsMetiers'] != null) {
57 commentaireCorpsMetiers = new List<Null>();
58 json['commentaire_corpsMetiers'].forEach((v) {
59 commentaireCorpsMetiers.add(new Null.fromJson(v));
60 });
61 }
62 post = json['post'];
63 if (json['sous_post'] != null) {
64 sousPost = new List<Null>();
65 json['sous_post'].forEach((v) {
66 sousPost.add(new Null.fromJson(v));
67 });
68 }
69 if (json['votes'] != null) {
70 votes = new List<Null>();
71 json['votes'].forEach((v) {
72 votes.add(new Null.fromJson(v));
73 });
74 }
75 if (json['likes'] != null) {
76 likes = new List<Null>();
77 json['likes'].forEach((v) {
78 likes.add(new Null.fromJson(v));
79 });
80 }
81 }
82
83 Map<String, dynamic> toJson() {
84 final Map<String, dynamic> data = new Map<String, dynamic>();
85 data['id_post'] = this.idPost;
86 data['date_post'] = this.datePost;
87 data['object_post'] = this.objectPost;
88 data['contenu_post'] = this.contenuPost;
89 data['latitude'] = this.latitude;
90 data['longitude'] = this.longitude;
91 if (this.fichiers != null) {
92 data['fichiers'] = this.fichiers.map((v) => v.toJson()).toList();
93 }
94 data['domaine'] = this.domaine;
95 if (this.partages != null) {
96 data['partages'] = this.partages.map((v) => v.toJson()).toList();
97 }
98 data['user'] = this.user;
99 if (this.commentaireCorpsMetiers != null) {
100 data['commentaire_corpsMetiers'] =
101 this.commentaireCorpsMetiers.map((v) => v.toJson()).toList();
102 }
103 data['post'] = this.post;
104 if (this.sousPost != null) {
105 data['sous_post'] = this.sousPost.map((v) => v.toJson()).toList();
106 }
107 if (this.votes != null) {
108 data['votes'] = this.votes.map((v) => v.toJson()).toList();
109 }
110 if (this.likes != null) {
111 data['likes'] = this.likes.map((v) => v.toJson()).toList();
112 }
113 return data;
114 }
115}
116
1class BusinessProfileEditModel {
2 String name;
3 String address;
4 String email;
5 String phoneNumber;
6 String rcNumber;
7 String businessRegistrationTypeKey;
8 String businessVerticalKey;
9 String countryKey;
10 String lgaKey;
11
12 BusinessProfileEditModel(
13 {this.name,
14 this.address,
15 this.email,
16 this.phoneNumber,
17 this.rcNumber,
18 this.businessRegistrationTypeKey,
19 this.businessVerticalKey,
20 this.countryKey,
21 this.lgaKey});
22
23 BusinessProfileEditModel.fromJson(Map<String, dynamic> json) {
24 name = json['name'];
25 address = json['address'];
26 email = json['email'];
27 phoneNumber = json['phoneNumber'];
28 rcNumber = json['rcNumber'];
29 businessRegistrationTypeKey = json['businessRegistrationTypeKey'];
30 businessVerticalKey = json['businessVerticalKey'];
31 countryKey = json['countryKey'];
32 lgaKey = json['lgaKey'];
33 }
34
35 Map<String, dynamic> toJson() {
36 final Map<String, dynamic> data = new Map<String, dynamic>();
37 data['name'] = this.name;
38 data['address'] = this.address;
39 data['email'] = this.email;
40 data['phoneNumber'] = this.phoneNumber;
41 data['rcNumber'] = this.rcNumber;
42 data['businessRegistrationTypeKey'] = this.businessRegistrationTypeKey;
43 data['businessVerticalKey'] = this.businessVerticalKey;
44 data['countryKey'] = this.countryKey;
45 data['lgaKey'] = this.lgaKey;
46 return data;
47 }
48}
49