Answers for "json to dart"

-1

dart map to json string

import 'dart:convert';
...
json.encode(data); // JSON.encode(data) in Dart 1.x
Posted by: Guest on October-09-2020
1

parse json to dart model

import 'dart:convert';

main() {
  String nestedObjText =
      '{"title": "Dart Tutorial", "description": "Way to parse Json", "author": {"name": "bezkoder", "age": 30}}';

  Tutorial tutorial = Tutorial.fromJson(jsonDecode(nestedObjText));

  print(tutorial);
Posted by: Guest on January-22-2021
1

json to dart

class Autogenerated {
  int userId;
  int id;
  String title;
  String body;

  Autogenerated({this.userId, this.id, this.title, this.body});

  Autogenerated.fromJson(Map<String, dynamic> json) {
    userId = json['userId'];
    id = json['id'];
    title = json['title'];
    body = json['body'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['userId'] = this.userId;
    data['id'] = this.id;
    data['title'] = this.title;
    data['body'] = this.body;
    return data;
  }
}
Posted by: Guest on June-29-2021
0

json to dart

class posts {
  int idPost;
  String datePost;
  String objectPost;
  String contenuPost;
  double latitude;
  double longitude;
  List<Null> fichiers;
  Null domaine;
  List<Null> partages;
  Null user;
  List<Null> commentaireCorpsMetiers;
  Null post;
  List<Null> sousPost;
  List<Null> votes;
  List<Null> likes;

  posts(
      {this.idPost,
      this.datePost,
      this.objectPost,
      this.contenuPost,
      this.latitude,
      this.longitude,
      this.fichiers,
      this.domaine,
      this.partages,
      this.user,
      this.commentaireCorpsMetiers,
      this.post,
      this.sousPost,
      this.votes,
      this.likes});

  posts.fromJson(Map<String, dynamic> json) {
    idPost = json['id_post'];
    datePost = json['date_post'];
    objectPost = json['object_post'];
    contenuPost = json['contenu_post'];
    latitude = json['latitude'];
    longitude = json['longitude'];
    if (json['fichiers'] != null) {
      fichiers = new List<Null>();
      json['fichiers'].forEach((v) {
        fichiers.add(new Null.fromJson(v));
      });
    }
    domaine = json['domaine'];
    if (json['partages'] != null) {
      partages = new List<Null>();
      json['partages'].forEach((v) {
        partages.add(new Null.fromJson(v));
      });
    }
    user = json['user'];
    if (json['commentaire_corpsMetiers'] != null) {
      commentaireCorpsMetiers = new List<Null>();
      json['commentaire_corpsMetiers'].forEach((v) {
        commentaireCorpsMetiers.add(new Null.fromJson(v));
      });
    }
    post = json['post'];
    if (json['sous_post'] != null) {
      sousPost = new List<Null>();
      json['sous_post'].forEach((v) {
        sousPost.add(new Null.fromJson(v));
      });
    }
    if (json['votes'] != null) {
      votes = new List<Null>();
      json['votes'].forEach((v) {
        votes.add(new Null.fromJson(v));
      });
    }
    if (json['likes'] != null) {
      likes = new List<Null>();
      json['likes'].forEach((v) {
        likes.add(new Null.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['id_post'] = this.idPost;
    data['date_post'] = this.datePost;
    data['object_post'] = this.objectPost;
    data['contenu_post'] = this.contenuPost;
    data['latitude'] = this.latitude;
    data['longitude'] = this.longitude;
    if (this.fichiers != null) {
      data['fichiers'] = this.fichiers.map((v) => v.toJson()).toList();
    }
    data['domaine'] = this.domaine;
    if (this.partages != null) {
      data['partages'] = this.partages.map((v) => v.toJson()).toList();
    }
    data['user'] = this.user;
    if (this.commentaireCorpsMetiers != null) {
      data['commentaire_corpsMetiers'] =
          this.commentaireCorpsMetiers.map((v) => v.toJson()).toList();
    }
    data['post'] = this.post;
    if (this.sousPost != null) {
      data['sous_post'] = this.sousPost.map((v) => v.toJson()).toList();
    }
    if (this.votes != null) {
      data['votes'] = this.votes.map((v) => v.toJson()).toList();
    }
    if (this.likes != null) {
      data['likes'] = this.likes.map((v) => v.toJson()).toList();
    }
    return data;
  }
}
Posted by: Guest on September-23-2021
1

json to dart

class Autogenerated {
  int postId;
  int id;
  String name;
  String email;
  String body;

  Autogenerated({this.postId, this.id, this.name, this.email, this.body});

  Autogenerated.fromJson(Map<String, dynamic> json) {
    postId = json['postId'];
    id = json['id'];
    name = json['name'];
    email = json['email'];
    body = json['body'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['postId'] = this.postId;
    data['id'] = this.id;
    data['name'] = this.name;
    data['email'] = this.email;
    data['body'] = this.body;
    return data;
  }
}
Posted by: Guest on February-10-2021
0

json to dart

class BusinessProfileEditModel {
  String name;
  String address;
  String email;
  String phoneNumber;
  String rcNumber;
  String businessRegistrationTypeKey;
  String businessVerticalKey;
  String countryKey;
  String lgaKey;

  BusinessProfileEditModel(
      {this.name,
      this.address,
      this.email,
      this.phoneNumber,
      this.rcNumber,
      this.businessRegistrationTypeKey,
      this.businessVerticalKey,
      this.countryKey,
      this.lgaKey});

  BusinessProfileEditModel.fromJson(Map<String, dynamic> json) {
    name = json['name'];
    address = json['address'];
    email = json['email'];
    phoneNumber = json['phoneNumber'];
    rcNumber = json['rcNumber'];
    businessRegistrationTypeKey = json['businessRegistrationTypeKey'];
    businessVerticalKey = json['businessVerticalKey'];
    countryKey = json['countryKey'];
    lgaKey = json['lgaKey'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['name'] = this.name;
    data['address'] = this.address;
    data['email'] = this.email;
    data['phoneNumber'] = this.phoneNumber;
    data['rcNumber'] = this.rcNumber;
    data['businessRegistrationTypeKey'] = this.businessRegistrationTypeKey;
    data['businessVerticalKey'] = this.businessVerticalKey;
    data['countryKey'] = this.countryKey;
    data['lgaKey'] = this.lgaKey;
    return data;
  }
}
Posted by: Guest on May-25-2021

Code answers related to "Dart"

Browse Popular Code Answers by Language