Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

json data to dart

class Autogenerated {
  Id iId;
  String name;
  String email;
  String password;
  String address;
  String type;
  List<Null> cart;
  V vV;

  Autogenerated(
      {this.iId,
      this.name,
      this.email,
      this.password,
      this.address,
      this.type,
      this.cart,
      this.vV});

  Autogenerated.fromJson(Map<String, dynamic> json) {
    iId = json['_id'] != null ? new Id.fromJson(json['_id']) : null;
    name = json['name'];
    email = json['email'];
    password = json['password'];
    address = json['address'];
    type = json['type'];
    if (json['cart'] != null) {
      cart = new List<Null>();
      json['cart'].forEach((v) {
        cart.add(new Null.fromJson(v));
      });
    }
    vV = json['__v'] != null ? new V.fromJson(json['__v']) : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    if (this.iId != null) {
      data['_id'] = this.iId.toJson();
    }
    data['name'] = this.name;
    data['email'] = this.email;
    data['password'] = this.password;
    data['address'] = this.address;
    data['type'] = this.type;
    if (this.cart != null) {
      data['cart'] = this.cart.map((v) => v.toJson()).toList();
    }
    if (this.vV != null) {
      data['__v'] = this.vV.toJson();
    }
    return data;
  }
}

class Id {
  String oid;

  Id({this.oid});

  Id.fromJson(Map<String, dynamic> json) {
    oid = json['$oid'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['$oid'] = this.oid;
    return data;
  }
}

class V {
  String numberInt;

  V({this.numberInt});

  V.fromJson(Map<String, dynamic> json) {
    numberInt = json['$numberInt'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['$numberInt'] = this.numberInt;
    return data;
  }
}
Source by jsontodart.com #
 
PREVIOUS NEXT
Tagged: #json #data #dart
ADD COMMENT
Topic
Name
3+6 =