Skip to content

Instantly share code, notes, and snippets.

@nvkiet
Created August 16, 2014 07:34
Show Gist options
  • Select an option

  • Save nvkiet/124ebbc6e55f68447349 to your computer and use it in GitHub Desktop.

Select an option

Save nvkiet/124ebbc6e55f68447349 to your computer and use it in GitHub Desktop.
[Swift] Convert AnyObject to JSON String
class LINJSONHelper {
class func jsonStringWithObject(obj: AnyObject) -> String? {
var error: NSError?
let jsonData = NSJSONSerialization.dataWithJSONObject(obj, options: NSJSONWritingOptions(0), error: &error)
if error != nil {
println("Error creating JSON data: \(error!.description)");
return nil
}
return NSString(data: jsonData, encoding: NSUTF8StringEncoding)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment