Created
March 4, 2020 06:50
-
-
Save haidar786/7cccd5d0862c2bc679c29fcb00538220 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"id": 1, | |
"name": "Smith", | |
"color": "Green", | |
"pets": [ | |
{ | |
"id": 1, | |
"breed": "Rottweiler", | |
"name": "Mackie", | |
"age": 8 | |
}, | |
{ | |
"id": 2, | |
"breed": "Mastiff", | |
"name": "Tanner", | |
"age": 8 | |
} | |
] | |
} | |
class House { | |
int id; | |
String name; | |
String color; | |
List<Pets> pets; | |
House({this.id, this.name, this.color, this.pets}); | |
House.fromJson(Map<String, dynamic> json) { | |
id = json['id']; | |
name = json['name']; | |
color = json['color']; | |
if (json['pets'] != null) { | |
pets = new List<Pets>(); | |
json['pets'].forEach((v) { | |
pets.add(new Pets.fromJson(v)); | |
}); | |
} | |
} | |
Map<String, dynamic> toJson() { | |
final Map<String, dynamic> data = new Map<String, dynamic>(); | |
data['id'] = this.id; | |
data['name'] = this.name; | |
data['color'] = this.color; | |
if (this.pets != null) { | |
data['pets'] = this.pets.map((v) => v.toJson()).toList(); | |
} | |
return data; | |
} | |
} | |
class Pets { | |
int id; | |
String breed; | |
String name; | |
int age; | |
Pets({this.id, this.breed, this.name, this.age}); | |
Pets.fromJson(Map<String, dynamic> json) { | |
id = json['id']; | |
breed = json['breed']; | |
name = json['name']; | |
age = json['age']; | |
} | |
Map<String, dynamic> toJson() { | |
final Map<String, dynamic> data = new Map<String, dynamic>(); | |
data['id'] = this.id; | |
data['breed'] = this.breed; | |
data['name'] = this.name; | |
data['age'] = this.age; | |
return data; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment