0

I've done this before, but can't remember how its done now.

Have one json response from foursquare which includes:

"hereNow"=>{"count"=>1, "groups"=>[{"type"=>"friends", "name"=>"friends here", "count"=>0, "items"=>[]}, ...]}

I respond with @place (which is the location info) but want to pass the names and images to my view as json.

thought is was something like @place['hereNow'] << response['venue']['hereNow'] to include it to my render :json => @place

1
  • What is @place['hereNow'] before you assign to it? What do you want it to be? Commented Jul 9, 2011 at 14:43

1 Answer 1

1

Well the point is: the received json is a string so you can't work on it directly.

So two steps here:

  • convert the received json to a Hash

  • easily add whatever you desire to the Hash

  • convert the hash back to json

There are great examples here.

In a nutshell:

j = ActiveSupport::JSON
hash = { :color => ["red", "green", "jellow"], :date => Time.now }
json_string    = j.encode hash
recreated_hash = j.decode json_string    
Sign up to request clarification or add additional context in comments.

1 Comment

for me it was as simple as hash = { :hereNow => response['venue']['hereNow'] }. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.