Skip to content

Instantly share code, notes, and snippets.

@Thunderbird7
Last active December 29, 2015 11:44
Show Gist options
  • Save Thunderbird7/5a47ee213f3a38460e80 to your computer and use it in GitHub Desktop.
Save Thunderbird7/5a47ee213f3a38460e80 to your computer and use it in GitHub Desktop.
Deserialize json string UTF8 encoding
//: Playground - noun: a place where people can play
import UIKit
let jsonString = "{\"username\" : \"thunderbird\", \"password\" : \"tb00110\"}"
func jsonDecodeString(json: String) -> Dictionary<String, AnyObject>? {
let json:NSData = jsonString.dataUsingEncoding(NSUTF8StringEncoding)!
do {
return try NSJSONSerialization.JSONObjectWithData(json, options: NSJSONReadingOptions.MutableContainers) as? Dictionary<String, AnyObject>
} catch {
print("error")
}
return nil
}
jsonDecodeString(jsonString)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment