I get a list of countries from a web service. After receiving it, I used this code to process it:
if let json = try NSJSONSerialization.JSONObjectWithData(data!, options: []) as? NSDictionary { // triggering callback function that should be processed in the call // doing logic } else { if let json = try NSJSONSerialization.JSONObjectWithData(data!, options:[]) as? AnyObject { completion(json) } else { let jsonStr = NSString(data: data!, encoding: NSUTF8StringEncoding) print("Error could not parse JSON string: \(jsonStr)") } }
And after that, the list looks like this (it ends in this part of NSJSONSerialization.JSONObjectWithData(data!, options:[]) as? AnyObject ):
Optional(( { "country_code" = AF; "dial_code" = 93; id = 1; name = Afghanistan; }, { "country_code" = DZ; "dial_code" = 213; id = 3; name = Algeria; }, { "country_code" = AD; "dial_code" = 376; id = 4; name = Andorra; } ))
Now I have to convert this json object to an array (or NSDictionary) and skip it. Can anyone advise how?
ios swift swift2
bla0009 Nov 03 '15 at 21:13 2015-11-03 21:13
source share