I'm trying to use the google image API with JSON (https://developers.google.com/image-search/v1/jsondevguide) to get the URL of the first image that shows when searching something. This is what I have:
let placeName = "New York"
func getImage() {
let url = NSURL(string: "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=\(placeName)")
let request = NSURLRequest(URL: url!)
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()){ (response, go, error) -> Void in
let go = NSJSONSerialization.JSONObjectWithData(go, options: NSJSONReadingOptions.AllowFragments, error: nil) as [String:AnyObject]
let responseData = go["responseData"] as [String:AnyObject]
// let results = responseData["results"] as [String:AnyObject]
// let imageURL = results["unescapedUrl"] as String
println(responseData)
}
}
The responseData part is as far as I can go (that then returns everything), but trying to go one level deeper (to "results") will crash it.