Last active
December 29, 2015 11:44
-
-
Save Thunderbird7/5a47ee213f3a38460e80 to your computer and use it in GitHub Desktop.
Deserialize json string UTF8 encoding
This file contains 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
//: 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