Saturday, 15 March 2014

How do I return JSON in the proper format in Ruby? -


When I try to return JSON in the format shown above, my JSON looks like this True, \ "rating \": 3.5, \ "mobile_url \": \ "http: //m.yelp .com / biz / rudys-barbershop-seattle \ ", ...

When I use" p result "(without .to_json), me down Finds:

  "is_claimed" = & gt; True, "Rating" = & gt; 3.5, "mobile_url" = & gt; "Http://m.yelp.com/biz/rudys-barbershop-seattle", ....   

The first is a '\' character and the second uses a hash rocket. How can I return JSON in a typical format?

The format you are looking for is the same reason p of output Information, try changing your output to puts .

  data = '{"is_claimed": true, "rating": 3.5, "Mobile_url": "http://m.yelp.com/biz/rudys-barbershop-seattle"} 'Result = JSON. Pars (Data) results. To_json   

Edit: Some additional information on p vs puts :

No comments:

Post a Comment