my friends have encountered a problem. Thank you very much for reading I use the library swiftyJson and my swift version is 3
{
"result": [
{
"id": 427,
"tracking_code": "4271547641283",
"payments": "45,000",
"items": [
{
"service": "خدمات آرایش کودک کات (اصلاح مو) شستشو و حالت دهی مو",
"price": "25000.00",
"total_price": "25000.00",
"quantity": "1"
},
{
"service": "خدمات آرایش کودک کات (اصلاح مو و سشوار)",
"price": "20000.00",
"total_price": "20000.00",
"quantity": "1"
}
],
"address": "تهران سعادت آباد خیابان ابریشم ۴ شرق پ ۱۲",
"postal_code": "۳۴۵۶۷۲۴۳8",
"phone": "09381576103",
"status": "در انتظار پرداخت",
"online": "1",
"approved": "درخواست تایید شده است",
"rate": null,
"approved_user": {
"id": 36,
"image": "http://www.tipchin.com/assets/uploads/user/medium/84afccebc7ef8e9cf3cd2066036cefc6.jpg",
"name": "tets",
"family": "تستی",
"birthday": "1373/9/27",
"services": [
"پیرایش مو، ابرو و اصلاح صورت",
"خدمات آرایش داماد",
"خدمات آرایش کودک",
"گریم و متعادل سازی چهره",
"خدمات ویژه مو",
"خدمات پوست و زیبایی",
"میکرو اسکالپ",
"نگهداری و زیبایی مو"
]
},
"date_request": "۱۳۹۷/۱۰/۲۹ ۰۴:۲۰",
"created_at": "۱۳۹۷/۱۰/۲۶ ۱۵:۵۱"
}
]
}
How can I get the value of [approved_user"][" id "] with swifty json?
First, I hope you have json in SwiftyJson format JSON
let json = JSON(data)
Ok, so first you have to get array for key "result"
json["result"]
then we need some element from this array, so we have to specify index of it
json["result"][0]
then we need object for key "approved_user"
json["result"][0]["approved_user"]
and now we can get its id property
json["result"][0]["approved_user"]["id"]
So:
let id = json["result"][0]["approved_user"]["id"].intValue
Anyway, I would suggest you to start using Swift 4+, since you can learn with Codable
and then your iOS programming life will be much easier. ;)