json - rails best way to extract values from response hash -


i'm having problems extracting values in response hash call google image search api.

i want value url key each result.

i figured i'd call deep_symbolize_keys on response , hash.results.url , doesn't work. feel i'm doing stupid, pointers welcome.

controller code

_url = 'http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=fuzzy%20monkey' _response = net::http.get_response(uri.parse(_url)) @response_hash = json.parse _response.body 

response hash before keyed stored in @response_hash

"responsedata": {     "results": [         {             "gsearchresultclass": "gimagesearch",             "width": "1152",             "height": "864",             "imageid": "and9gcqqigy-u6ktxke82n5hma5qvfm2uyvnkgtjme6pkzgl_1gym--yb90oqnoj",             "tbwidth": "150",             "tbheight": "113",             "unescapedurl": "http://www.blirk.net/wallpapers/1152x864/fuzzy-monkey-1.jpg",             "url": "http://www.blirk.net/wallpapers/1152x864/fuzzy-monkey-1.jpg",             "visibleurl": "www.blirk.net",             "title": "<b>fuzzy monkey</b> normal 1152x864",             "titlenoformatting": "fuzzy monkey normal 1152x864",             "originalcontexturl": "http://www.blirk.net/fuzzy-monkey/1/1152x864/",             "content": "<b>fuzzy monkey</b> normal 1152x864",             "contentnoformatting": "fuzzy monkey normal 1152x864",             "tburl": "http://t1.gstatic.com/images?q=tbn:and9gcqqigy-u6ktxke82n5hma5qvfm2uyvnkgtjme6pkzgl_1gym--yb90oqnoj"         },         {             "gsearchresultclass": "gimagesearch",             "width": "600",             "height": "397",             "imageid": "and9gcrpzyxxwbk0tjuu6pcdvrgru7qckcjq5dp96iylc6ulx1bqn4evbzdflck",             "tbwidth": "135",             "tbheight": "89",             "unescapedurl": "http://www.acuteaday.com/blog/wp-content/uploads/2011/05/fuzzy-snub-nosed-monkey.jpg",             "url": "http://www.acuteaday.com/blog/wp-content/uploads/2011/05/fuzzy-snub-nosed-monkey.jpg",             "visibleurl": "www.acuteaday.com",             "title": "<b>monkeys</b> » cute day",             "titlenoformatting": "monkeys » cute day",             "originalcontexturl": "http://www.acuteaday.com/blog/category/monkeys/",             "content": "<b>monkeys</b> » cute day",             "contentnoformatting": "monkeys » cute day",             "tburl": "http://t1.gstatic.com/images?q=tbn:and9gcrpzyxxwbk0tjuu6pcdvrgru7qckcjq5dp96iylc6ulx1bqn4evbzdflck"         },         {             "gsearchresultclass": "gimagesearch",             "width": "800",             "height": "600",             "imageid": "and9gcqgs5bxewnbiqhm5vl6dvapcqkopwn8hrqxndbiuq54hfoxzhbbtgu2wpe",             "tbwidth": "143",             "tbheight": "107",             "unescapedurl": "http://wild-facts.com/wp-content/uploads/2010/09/woolly_monkey1.jpg",             "url": "http://wild-facts.com/wp-content/uploads/2010/09/woolly_monkey1.jpg",             "visibleurl": "www.wild-facts.com",             "title": "facts woolly <b>monkey</b> | wild facts",             "titlenoformatting": "facts woolly monkey | wild facts",             "originalcontexturl": "http://www.wild-facts.com/2010/wild-fact-723-it-is-not-a-fuzzy-monkey-woolly-monkey/",             "content": "facts woolly <b>monkey</b> | wild facts",             "contentnoformatting": "facts woolly monkey | wild facts",             "tburl": "http://t1.gstatic.com/images?q=tbn:and9gcqgs5bxewnbiqhm5vl6dvapcqkopwn8hrqxndbiuq54hfoxzhbbtgu2wpe"         },         {             "gsearchresultclass": "gimagesearch",             "width": "1200",             "height": "1600",             "imageid": "and9gcqvihn2ozrnr6ujdqsbknsv2hexaua-lp5x22usdcyzmtsolc97nfjxavab",             "tbwidth": "113",             "tbheight": "150",             "unescapedurl": "http://4.bp.blogspot.com/_q6jkicszar0/tn1a8blugvi/aaaaaaaadoa/nyc1xl8bnoc/s1600/fuzzy+monkey+017.jpg",             "url": "http://4.bp.blogspot.com/_q6jkicszar0/tn1a8blugvi/aaaaaaaadoa/nyc1xl8bnoc/s1600/fuzzy%2bmonkey%2b017.jpg",             "visibleurl": "www.inkingpink.com",             "title": "inkingpink: <b>fuzzy monkey</b>",             "titlenoformatting": "inkingpink: fuzzy monkey",             "originalcontexturl": "http://www.inkingpink.com/2010/11/fuzzy-monkey.html",             "content": "inkingpink: <b>fuzzy monkey</b>",             "contentnoformatting": "inkingpink: fuzzy monkey",             "tburl": "http://t0.gstatic.com/images?q=tbn:and9gcqvihn2ozrnr6ujdqsbknsv2hexaua-lp5x22usdcyzmtsolc97nfjxavab"         }     ],     "cursor": {         "resultcount": "2,990,000",         "pages": [             {                 "start": "0",                 "label": 1             },             {                 "start": "4",                 "label": 2             },             {                 "start": "8",                 "label": 3             },             {                 "start": "12",                 "label": 4             },             {                 "start": "16",                 "label": 5             },             {                 "start": "20",                 "label": 6             },             {                 "start": "24",                 "label": 7             },             {                 "start": "28",                 "label": 8             }         ],         "estimatedresultcount": "2990000",         "currentpageindex": 0,         "moreresultsurl": "http://www.google.com/images?oe=utf8&ie=utf8&source=uds&start=0&hl=en&q=fuzzy+monkey",         "searchresulttime": "0.21"     } }, "responsedetails": null, "responsestatus": 200 

}

are looking this?

urls = _response["responsedata"]["results"].map { |result| result["url"] } 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -