Monday 15 February 2010

How do I parse JSON with Ruby on Rails? -


I'm looking for an easy way to parse JSON, want to extract a value and write it in a database in Rail I am

What I see especially, there is a way to remove shortUrl from JSON back to the bit.ly API:

  {" Errorcode ": 0," error message ":" "," result ": {" http://www.foo.com ": {" hash ":" e5TEd "," shortKeywordUrl ":" "," shortUrl ": "Http: //bit.ly/1a0p8G", "userHash": "1a0p8G"}}, "status code": "OK"}  

and then take that short URL and Write it in an active recorder object attached to long URL.

This is one of those things that can completely think through concept and when I sit then I know that I have to learn a lot.

These answers are a bit dated, so I'll give you:

  hash = JSON.parse string  < / Pre> 

Rail should automatically load the json module for you, so no should be to 'json' .


No comments:

Post a Comment