0
  @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.

enter image description here

4
  • @rubyprince check the code..venue['name']['location'][0]['address'] //issues venue['name']['categories'][0]['id'] //issues are not working Commented Jun 6, 2011 at 16:09
  • 2
    Maybe you should include the actual JSON (preferably nicely formatted for easy reading) rather than a screenshot. Commented Jun 6, 2011 at 16:11
  • @mu really.. i.sstatic.net/b58XS.png is this not clear enough..If i try to copy json.. alignment issues. Its foursquare venue api response. Commented Jun 6, 2011 at 16:13
  • It is difficult to parse the structure of text from a screenshot, it would have been easier if you pasted the JSON into a text editor, reformatted it to look similar to the screen shot, and then pasted that in your question as a code block. In any case, I think I have found the source of your problem. Commented Jun 6, 2011 at 16:19

1 Answer 1

2

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']
Sign up to request clarification or add additional context in comments.

1 Comment

+1 from me. If venue['name']['categories'] worked categories would have to be nested under name.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.