Skip to content

Instantly share code, notes, and snippets.

@PoojaB26
Created October 5, 2018 11:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PoojaB26/7514317181f81a00a36fbef596d506e6 to your computer and use it in GitHub Desktop.
Save PoojaB26/7514317181f81a00a36fbef596d506e6 to your computer and use it in GitHub Desktop.
Post model GET post/1
// To parse this JSON data, do
//
// final post = postFromJson(jsonString);
import 'dart:convert';
Post postFromJson(String str) {
final jsonData = json.decode(str);
return Post.fromJson(jsonData);
}
String postToJson(Post data) {
final dyn = data.toJson();
return json.encode(dyn);
}
class Post {
int userId;
int id;
String title;
String body;
Post({
this.userId,
this.id,
this.title,
this.body,
});
factory Post.fromJson(Map<String, dynamic> json) => new Post(
userId: json["userId"],
id: json["id"],
title: json["title"],
body: json["body"],
);
Map<String, dynamic> toJson() => {
"userId": userId,
"id": id,
"title": title,
"body": body,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment