How to get the data inside the json curly braces? Swift -
i can result , message data can't "crew_name" inside "crew". how can data if inside curly braces?
(json printed on console)
{ crew = { "crew_avatar" = "http://ec2-52-221-231-3.ap-southeast-1.compute.amazonaws.com/gv/images/profile_image/pang_kang_ming_916210_0e9.jpg"; "crew_contact" = 0123456789; "crew_email" = "pang@xover.com.my"; "crew_gender" = male; "crew_id" = pp000001; "crew_name" = "pang kang ming"; "crew_preferred_name" = pkm; "crew_qrcode" = "images/qrcode/qrcode_085960293a5378a64bec6ebfa3c89bb7.png"; }; message = "login sucessfully"; result = success;
}
@iboutlet var empnamelabel: uilabel! @iboutlet var empidlabel: uilabel! override func viewdidload() { super.viewdidload() let empnamevalue = user!("crew"["crew_name"])as? string let empidvalue = user!["result"]as? string empnamelabel.text = empnamevalue empidlabel.text = empnamevalue }
the code inside curly braces dictionary, can access first creating dictionary "crew" key, , accessing "crew_name" through that.
assuming user
variable correctly created json data can following access "crew_name":
if let crew = user!["crew"] as? [string:any], let crewname = crew["crew_name"] as? string { print(crewname) // output: "pang kang ming" }
Comments
Post a Comment