ios - How to pasre JSON (dictionary and array) using the new Swift 3 and Alamofire -


can 1 suggest , send me sample code fetching json response. few apis getting data in form of nsdictionary , few apis getting data in form of nsarray.

this api request alamofire.

apimanager.sharedinstance.getteacherprofiledatafromurl(){(userjson)-> void in           let swiftyjsonvar = json(userjson)         print("userjson userjson userjson userjson",userjson)          print("swiftyjsonvar",swiftyjsonvar) } 

1) api json array of data

{     "status": 1,     “student”: [         {             "name": "sprouse",             "subject": [                 “english”             ],             "personal_email": "",             "school_email": "cole.sprouse483@demo.in",             "phone": "9665478544",             "class_teacher": false,             "image": "/assets/default_male.png"         },         {             "name": “elen”,             "subject": [                 "social science"             ],             "personal_email": "",             "school_email": "elena.gilbert564@demo.in",             "phone": "9066260799",             "class_teacher": false,             "image": "/assets/default_female.png"         },             ],     "message": "details fetched successfully." } 

2) api json dictionary of data

{     "status": 1,     "dashboard": {         "announcement": [             {                 "title": "independence day celebration",                 "posted_on": "13 august, 2017"             }         ],         "student": {             "attendance_percent": 100,             "assignment": [                 {                     "title": "alphabets in hindi",                     "end_date": "13/09/2017",                     "subject": "hindi",                     "teacher_name": "bonnie bennette"                 }             ],             "leave_apply": 13         },         "image": "/system/images/86/j1f9diji_thumb.jpg?1504593436"     },     "message": "details fetched successfully." } 

1) api json array of data

let swiftyjsonvar = json(userjson) let array : [[string : string]] = swiftyjsonvar["student"] 

this give array of dictionaries or key-values of student. further can value array that

let name : string = array[0]["name"] 

2) another api json dictionary of data

let swiftyjsonvar = json(userjson) let dictionary : [[string : string]] = swiftyjsonvar["dashboard"] 

this give array of dictionary or key-value of dashboard.

let array : [[string : string]] = dictionary["announcement"] 

this give array of announcement , next can further values this

let name : array = array[0]["title"] 

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -