How to Access Arrays with a JSON Hash?
So I am trying to access the "country_code" field, but i开发者_JAVA百科t is an array within the :businesses hash, so I have no idea how to access it/make it a hash to access it
{:message=>{"text"=>"OK", "code"=>0, "version"=>"1.1.1"}, :businesses=>[{"rating_img_url"=>"http://media1.ct.yelpcdn.com/static/201012164084228337/i/ico/stars/stars_4.png", "country_code"=>"US",
obj = ActiveSupport::JSON.decode(Net::HTTP.get_response(URI.parse("http://url")).body).to_options
You can try this:
obj[:businesses][0]['country_code']
country_code = obj[":businesses"][0].country_code
精彩评论