[
{
"id": 0,
"owner": {
"id": 0,
"email": "[email protected]",
"username": "string",
"phone": "string",
"is_active": true,
"is_staff": true,
"is_premium": true,
"active_status": 32767,
"auth_provider": "string",
"profile": {
"id": 0,
"user": "string",
"last_name": "string",
"first_name": "string",
"point": 2147483647,
"exp": 2147483647,
"streak": 2147483647,
"avatar_url": "string",
"gender": 0,
"birthdate": "2024-06-11T13:43:43.912Z",
"height": "-",
"weight": "04.0",
"bmi": "93.",
"level": 0,
"created_at": "2024-06-11T13:43:43.913Z",
"updated_at": "2024-06-11T13:43:43.913Z",
"active_status": 32767
},
"following": [
{
"id": 0,
"follower": 0,
"followed": 0
}
],
"created_at": "2024-06-11T13:43:43.913Z"
},
"title": "string",
"description": "string",
"image_url": "string",
"content": "string",
"benefit": "string",
"votes": [
{
"id": 0,
"user": "string",
"user_id": "string",
"blog": "string",
"vote_value": 2147483647
}
],
"created_at": "2024-06-11T13:43:43.913Z",
"updated_at": "2024-06-11T13:43:43.913Z",
"active_status": 2147483647
}
]
Is the data response I get.
Please help me to map data to use.
2
Answers
You can use quicktype.io and just paste your json and give a class name and it’ll generate your required model class.
You can play with the available options like:
Here’s the example of generated code from quicktype.io based on your json
So you can just paste those generated models in your code in a dart file.
And when you need to map the response you can just use something like this:
Actually the data that you provided is a List<Map<String,dynamic>> so the best way to parse this type of data is to use packages like json_serializable and build_runner for generating the code for the model of the data or either try to understand the data .if you see data stating with [ and ending with ] this is an list(Array) and if its start with { and ends with } it will be a map(object) so by this you can understand the structure of data you can use json.decode() for parsing it to dart data type if its json.