I have a JSON string (from PHP\'s json_encode()
that looks like this:
[{\"id\": \"1\", \"name\":\"Aaa\"}, {\"id\": \"2\", \"name\":\"Bbb\"}]
Swift 2.0 on Xcode 7 (Beta) with do/try/catch block:
// MARK: NSURLConnectionDataDelegate
func connectionDidFinishLoading(connection:NSURLConnection) {
do {
if let response:NSDictionary = try NSJSONSerialization.JSONObjectWithData(receivedData, options:NSJSONReadingOptions.MutableContainers) as? Dictionary {
print(response)
} else {
print("Failed...")
}
} catch let serializationError as NSError {
print(serializationError)
}
}