I'm trying to loop through this sample of JSON to get age, name and type using SwiftyJSON. I succeeded getting name and age but the type is hard for me. Can someone show me how to do it, please?
"both": [
{
"id": 130,
"name": "TMT",
"age": "2006",
"created_at": "2016-12-19 21:37:06",
"updated_at": "2016-12-19 21:37:06",
"pic": "1482183426.png",
"pivot": {
"user_id": 4,
"car_id": 130,
"type": "rent"
}
},
{
"id": 113,
"name": "TMT ",
"age": 2016,
"created_at": "2016-12-18 14:46:18",
"updated_at": "2016-12-18 14:47:41",
"pic": "",
"pivot": {
"user_id": 4,
"car_id": 113,
"type": "rent"
}
}
]
work
let json = JSON(value)
for (key, subJson) in json {
let cars = subJson["both"]
for (key, subJson) in cars {
print(subJson["age"])
}
All you need to is to access
pivotdictionary and read thetypekey from there.