Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // To parse this JSON data, do
- //
- // final userModel = userModelFromJson(jsonString);
- import 'dart:convert';
- List<UserModel> userModelFromJson(String str) => new List<UserModel>.from(json.decode(str).map((x) => UserModel.fromJson(x)));
- String userModelToJson(List<UserModel> data) => json.encode(new List<dynamic>.from(data.map((x) => x.toJson())));
- class UserModel {
- int id;
- String name;
- String username;
- String email;
- Address address;
- String phone;
- String website;
- Company company;
- UserModel({
- this.id,
- this.name,
- this.username,
- this.email,
- this.address,
- this.phone,
- this.website,
- this.company,
- });
- factory UserModel.fromJson(Map<String, dynamic> json) => new UserModel(
- id: json["id"],
- name: json["name"],
- username: json["username"],
- email: json["email"],
- address: Address.fromJson(json["address"]),
- phone: json["phone"],
- website: json["website"],
- company: Company.fromJson(json["company"]),
- );
- Map<String, dynamic> toJson() => {
- "id": id,
- "name": name,
- "username": username,
- "email": email,
- "address": address.toJson(),
- "phone": phone,
- "website": website,
- "company": company.toJson(),
- };
- }
- class Address {
- String street;
- String suite;
- String city;
- String zipcode;
- Geo geo;
- Address({
- this.street,
- this.suite,
- this.city,
- this.zipcode,
- this.geo,
- });
- factory Address.fromJson(Map<String, dynamic> json) => new Address(
- street: json["street"],
- suite: json["suite"],
- city: json["city"],
- zipcode: json["zipcode"],
- geo: Geo.fromJson(json["geo"]),
- );
- Map<String, dynamic> toJson() => {
- "street": street,
- "suite": suite,
- "city": city,
- "zipcode": zipcode,
- "geo": geo.toJson(),
- };
- }
- class Geo {
- String lat;
- String lng;
- Geo({
- this.lat,
- this.lng,
- });
- factory Geo.fromJson(Map<String, dynamic> json) => new Geo(
- lat: json["lat"],
- lng: json["lng"],
- );
- Map<String, dynamic> toJson() => {
- "lat": lat,
- "lng": lng,
- };
- }
- class Company {
- String name;
- String catchPhrase;
- String bs;
- Company({
- this.name,
- this.catchPhrase,
- this.bs,
- });
- factory Company.fromJson(Map<String, dynamic> json) => new Company(
- name: json["name"],
- catchPhrase: json["catchPhrase"],
- bs: json["bs"],
- );
- Map<String, dynamic> toJson() => {
- "name": name,
- "catchPhrase": catchPhrase,
- "bs": bs,
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement