Created
March 1, 2015 04:33
-
-
Save jquave/e01cc3b279a0c199d65a to your computer and use it in GitHub Desktop.
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
// 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