i am working on a way to parse json from the web in my app.
Source: http://api.randomuser.me/
My Code:
var bytes: NSMutableData?
@IBAction func loadJson(sender: AnyObject) {
let request = NSURLRequest(URL: NSURL(string: "http://api.randomuser.me/")!)
let loader = NSURLConnection(request: request, delegate: self, startImmediately: true)
}
func connection(didReceiveResponse: NSURLConnection!, didReceiveResponse response: NSURLResponse!) {
self.bytes = NSMutableData()
}
func connection(connection: NSURLConnection!, didReceiveData conData: NSData!) {
self.bytes?.appendData(conData)
}
func connectionDidFinishLoading(connection: NSURLConnection!) {
let jsonResult: Dictionary = NSJSONSerialization.JSONObjectWithData(self.bytes!, options: NSJSONReadingOptions.MutableContainers, error: nil) as! Dictionary<String, AnyObject>
let results: NSArray = jsonResult["results"]! as! NSArray
println(results)
for result in results {
// Works
println(result)
// Works
println(result["seed"])
// Does not work !!! why?
println(result["user"]["email"])
}
}
Why can't I get the email from the array?
If you want you can take a look at the json in the link above.
// Does not work !!! why?What does "does not work" mean?