How to get the multiple data inside the json curly braces? Swift -


how multiple data inside json curly braces in swift3?

can use code multiple data? (get "crew_id","crew_name","crew_email")

if let crew = user!["crew"] as? [string:any], let crewname = crew["crew_name"] as? string { print(crewname) 

json

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; 

yes can, add values want unwrap below, aware if 1 of optional binding not unwrap, if others unwrap if statement not executed, consider separating if statements.

depends on being returned in json.

if let crew = user!["crew"] as? [string:any], let crewname = crew["crew_name"] as? string, let crewid = crew["crew_id"] as? string {  print(crewname)  print(crewid) } 

recommended way, if values not present in json response, able other values.

   if let crew = user!["crew"] as? [string:any] {     if let crewname = crew["crew_name"] as? string {       print(crewname)     }     if let crewid = crew["crew_id"] as? string {       print(crewid)     }   } 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -