Skip to content

Instantly share code, notes, and snippets.

@jquave
Created March 1, 2015 04:24
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 jquave/77d9b69a5aa08119f76d to your computer and use it in GitHub Desktop.
Save jquave/77d9b69a5aa08119f76d to your computer and use it in GitHub Desktop.
// Complete code using LumaJSON
if let parsed = LumaJSON.parse(jsonStr) {
if let friend_ids = parsed["friend_ids"] as? [Int] {
println("Luma count: \(friend_ids.count)")
}
}
// Same functionality using built-in tools
var err: NSError?
if let jsonDeserialized = NSJSONSerialization.JSONObjectWithData(jsonData, options: .MutableLeaves, error: &err) as? NSDictionary {
if let friend_ids = jsonDeserialized["friend_ids"] as? [Int] {
println("Native count: \(friend_ids.count)")
}
}
else if (err != nil) {
println(err?.localizedDescription)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment