Skip to content

Instantly share code, notes, and snippets.

@rmangino
Created January 29, 2017 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmangino/b0fb9e7e738bb20d749fd490bdea592c to your computer and use it in GitHub Desktop.
Save rmangino/b0fb9e7e738bb20d749fd490bdea592c to your computer and use it in GitHub Desktop.
let json = "{\"foo\" : 5}"
let decoded = try! JSONSerialization.jsonObject(with: Data(json.utf8), options: []) as! [String : Any]
print(decoded)
if let int8 = decoded["foo"] as? Int8 {
print(int8)
}
else {
print("conversion failed")
}
// prints "conversation failed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment