TypeError while iterating through a Hash
Posted
by
Ved
on Stack Overflow
See other posts from Stack Overflow
or by Ved
Published on 2011-01-02T17:40:58Z
Indexed on
2011/01/02
17:53 UTC
Read the original article
Hit count: 282
ruby
I have the following hash:
{"groups"=>[{"type"=>"Nearby", "venues"=>[{"id"=>4450132, "name"=>"Position2", "address"=>"Domlur", "city"=>"Bangalore", "state"=>"Karnataka/India", "zip"=>"560037", "verified"=>false, "geolat"=>12.9566921, "geolong"=>77.6407258, "stats"=>{"herenow"=>"0"}, "twitter"=>"position2", "hasTodo"=>"false", "distance"=>0},...
I want to iterate through it and find all the 'name' attributes. My code looks like:
response["groups"]["Nearby"]["venues"].each do |key|
logger.debug key['name']
end
But I keep on getting error:
TypeError (can't convert String into Integer):
I am on ruby 1.9.
© Stack Overflow or respective owner