Chandan Jee Chandan Jee - 2 months ago 11
iOS Question

How to get NSDictionary from NSDictionary in Swift?

I am new in Swift.My json detail below.How to get dictionary of 'assdata' from AP0 Dictionary.Please detail briefly and step by step.

"AP0": {
"assdata": "{
\"Description\":\"Test\",
\"Service Requested\":\" Equipment\",
\"Requested For\":\"Chandan\",
\"Requested Location\":\"\\\\Locations\\\\SBCBSC\\\\ SBCBSC - MAIN\",
\"Requested By\":\"Chandan\",
\"Request Id\":\"100067809074\",
\"datastatus\":\"true\"}",
"Linked Form": "Equipment",
"System Record ID": "17213450626",
"Submitted By": "Chandan",
"Linked Business Object": "Request",
"Linked Record": "100067809074-0",
"datastatus": "true"
}


Thanks In Advance.

Answer

You can try this.

let myJSON =  try NSJSONSerialization.JSONObjectWithData(urlData!, options: NSJSONReadingOptions.MutableContainers) as! NSDictionary

            let keys = myJSON.allKeys
            print(keys)

            let values = myJSON.allValues
            print(values)

            let dict = values[2]
            print(dict)

            let dictAssdata = dict["assdata"]
            print(dictAssdata)

Hope it help you.