Created
July 4, 2021 05:43
-
-
Save achinverma/014d181caf41859a62200d6f5444fc65 to your computer and use it in GitHub Desktop.
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 postResponse = postResponseFromJson(jsonString); | |
import 'dart:convert'; | |
PostResponse postResponseFromJson(String str) => PostResponse.fromJson(json.decode(str)); | |
String postResponseToJson(PostResponse data) => json.encode(data.toJson()); | |
class PostResponse { | |
PostResponse({ | |
this.code, | |
this.data, | |
}); | |
int code; | |
List<Datum> data; | |
factory PostResponse.fromJson(Map<String, dynamic> json) => PostResponse( | |
code: json["code"], | |
data: List<Datum>.from(json["data"].map((x) => Datum.fromJson(x))), | |
); | |
Map<String, dynamic> toJson() => { | |
"code": code, | |
"data": List<dynamic>.from(data.map((x) => x.toJson())), | |
}; | |
} | |
class Datum { | |
Datum({ | |
this.id, | |
this.userId, | |
this.title, | |
this.body, | |
this.createdAt, | |
this.updatedAt, | |
}); | |
int id; | |
int userId; | |
String title; | |
String body; | |
DateTime createdAt; | |
DateTime updatedAt; | |
factory Datum.fromJson(Map<String, dynamic> json) => Datum( | |
id: json["id"], | |
userId: json["user_id"], | |
title: json["title"], | |
body: json["body"], | |
createdAt: DateTime.parse(json["created_at"]), | |
updatedAt: DateTime.parse(json["updated_at"]), | |
); | |
Map<String, dynamic> toJson() => { | |
"id": id, | |
"user_id": userId, | |
"title": title, | |
"body": body, | |
"created_at": createdAt.toIso8601String(), | |
"updated_at": updatedAt.toIso8601String(), | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment