Created
October 5, 2018 11:56
-
-
Save PoojaB26/7514317181f81a00a36fbef596d506e6 to your computer and use it in GitHub Desktop.
Post model GET post/1
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
// 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