I am having some difficulties with parsing the JSON from API. Previously the JSON format was simpler:
{ "author": {
"id": 4,
"username": "maria"
},
"description": "dsada",
"image": "/media/posts/image_cropper_1616320457204.jpg",
"created_at": "2021-03-21T09:54:38.645596Z"
},
{
"author": {
"id": 4,
"username": "maria"
},
"description": "asdsad",
"image": "/media/posts/image_cropper_1616070403137.jpg",
"created_at": "2021-03-18T12:26:56.774797Z"
}
And my model for that JSON format was the following
class Feed {
final String author;
final String description;
final String imageUrl;
final String createdAt;
Feed({this.author, this.description, this.imageUrl, this.createdAt});
factory Feed.fromJson(Map<String, dynamic> json) {
return Feed(
author: json['author']['username'],
description: json['description'],
imageUrl: json['image'],
createdAt: json['created_at'],
);
}
}
Recently the API was changed slightly to enable pagination. After that the I couldn't figure out a way to properly get that data from API in a correct format. New JSON format looks like this:
{
'count: 6,
'next': "/posts/list/?limit=5&offset=5",
'previous': null,'
'results': [
{ "author": {
"id": 4,
"username": "maria"
},
"description": "dsada",
"image": "/media/posts/image_cropper_1616320457204.jpg",
"created_at": "2021-03-21T09:54:38.645596Z"
},
{
"author": {
"id": 4,
"username": "maria"
},
"description": "asdsad",
"image": "/media/posts/image_cropper_1616070403137.jpg",
"created_at": "2021-03-18T12:26:56.774797Z"
}
]
}
I didn't think that after adding pagination the JSON format would change. If you have any idea to do this, kindly help. Thank you.