ruby - Iterating through JSON data from external API in Rails -


i have function return_summoner_champion_list(name) return following json data when called

[   {     "id"=>"1",     "name"=>"a"   },   {     "id"=>"2",     "name"=>"b"   },   , on... ] 

how iterate through json array , print out ids?

i tried

return_summoner_champion_list(name).each |list|   puts list["id"] end 

but still returns same json data above without changes.

i think you're looking array#collect not array#each:

return_summoner_champion_list(name).collect{|l| l['id']} => [1,2, ...] 

Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -