**`List populars = [
{ "image": "https://images.unsplash.com/photo-1600596542815-ffad4c1539a9?ixid=MXwxMjA3fDB8MHxzZWFyY2h8NHx8Zm9vZHxlbnwwfHwwfA==&ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60",
"photos": [ "https://images.unsplash.com/photo-1598928506311-c55ded91a20c?ixid=MXwxMjA3fDB8MHxzZWFyY2h8NHx8Zm9vZHxlbnwwfHwwfA==&ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60", "https://images.unsplash.com/photo-1576941089067-2de3c901e126?ixid=MXwxMjA3fDB8MHxzZWFyY2h8NHx8Zm9vZHxlbnwwfHwwfA==&ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60" ],
"name": "Single Villa",
"price": "280,000FCFA",
"location": "Phnom Penh, Cambodia",
"is_favorited": true,
"negotiatable": false,
"reviews": 128,
"description":
"We’re reimagining how you buy, sell and rent. It’s now easier to get into a place you love. So let’s do this, together.",
"features": [
{
"type": "Studio",
},
{
"rooms": 1,
},
{
"toilet": 1,
},
{
"parlor": 1,
},
{
"water": true,
}
]
}, ]`**
CodePudding user response:
I think you're tring to implement your code as Map.
In order to use your JSON format in Dart, you need to make it Map first.
Map map = populars.asMap();
Then you can use it like that:
print(map[key])
CodePudding user response:
try this if you want to get the data inside your created json either ways there are more ways to it.
final getFeatures = populars.map((e)=> e['features']).first;
print(getFeatures[0]['type']);
print(getFeatures[1]['rooms']);
print(getFeatures[2]['toilet']);
print(getFeatures[3]['parlor']);
print(getFeatures[4]['water']);
//Result
Studio
1
1
1
true
CodePudding user response:
I think the issue is in the structure itself, it should be like this:
{
"name": "Single Villa",
"features": {
"type": "Studio",
"rooms": 1,
"toilet": 1,
"parlor": 1,
"water": true
}
},
then you can use it like this:
final name = populars[index]['name'];
final rooms = populars[index]['features']['rooms'];
...
