I'm converting zip code data to city and state using http://api.zippopotam.us. I'm able to pull out the country easily, but the "place name" (city) and "state abbreviation" are giving me problems. Here's the code:
var url = NSURL(string: "http://api.zippopotam.us/us/90210")
let task = NSURLSession.sharedSession().dataTaskWithURL(url!, completionHandler: {(data, response, error) -> Void in
let jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as! NSDictionary
var placeDictionary = jsonResult["places"]! as? NSArray
println(placeDictionary) // this works
var name: String? = jsonResult[0]!.valueForKey("place name") as? String
println(name) // this doesn't.
})
task.resume()
I'm getting an error:
Unexpectedly found nil while unwrapping an Optional value
placeDictionaryat all ...