Created
August 16, 2014 07:34
-
-
Save nvkiet/124ebbc6e55f68447349 to your computer and use it in GitHub Desktop.
[Swift] Convert AnyObject to JSON String
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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