Reputation: 5890
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.
Upvotes: 1
Views: 1373
Reputation: 416
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.
Upvotes: 2
Reputation: 72410
Your key assdata
contains String JSON response so that for getting Dictionary from it you need to convert it to first data.
if let jsonStr = yourResponse["assdata"] as? String {
if let data = jsonStr.dataUsingEncoding(NSUTF8StringEncoding) {
do {
let dic = try NSJSONSerialization.JSONObjectWithData(data, options: []) as? [String:AnyObject]
} catch let error as NSError {
print(error)
}
}
}
Upvotes: 1