Skip to content

Instantly share code, notes, and snippets.

@jquave
Created March 1, 2015 04:33
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/e01cc3b279a0c199d65a to your computer and use it in GitHub Desktop.
Save jquave/e01cc3b279a0c199d65a to your computer and use it in GitHub Desktop.
// Using LumaJSON
if let parsed = LumaJSON.parse(jsonStr) {
if let firstCommentText = parsed["user"]?["comments"]?[0]?["text"] as? String {
println("Luma First comment \(firstCommentText)")
}
}
// Using built-in JSON decoder
var err: NSError?
if let jsonDeserialized = NSJSONSerialization.JSONObjectWithData(jsonData, options: .MutableLeaves, error: &err) as? NSDictionary {
if let user = jsonDeserialized["user"] as? NSDictionary {
if let comments = user["comments"] as? NSArray {
if let firstComment = comments[0] as? NSDictionary {
if let firstCommentText = firstComment["text"] as? String {
println("Normal First comment \(firstCommentText)")
}
}
}
}
}
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