@response = Typhoeus::Request.get(FOUR_SQUARE_开发者_运维技巧API_SERVER_ADDRESS+'search?ll=' + current_user.altitude.to_s + "&query="+ params[:query] + FOUR_SQUARE_API_ACESS_CODE)
@venues = ActiveSupport::JSON.decode(@response.body)
@venues['response']['groups'][0]['items'].each do |venue|
venue['name'] //working
venue['name']['location'][0]['address'] //issues
venue['name']['categories'][0]['id'] //issues
end
Please check inline comments for issues.
First of all, the venue['name']
is a scalar, not an array; secondly, venue['location']
(which I think you're trying to access) is not encoded as an array, that's just an object:
location: {
address: "...',
city: "...",
// ...
}
So here you want:
venue['location']
Then, your venue['name']['categories'][0]['id']
will fail because, again, venue['name']
is a scalar; for this one, you want:
venue['categories'][0]['id']
精彩评论