JSON string to rails hash
10,455
That's just because you're using "puts". If you just type fence_parsed
, or p fence_parsed
you'll get what you're looking for. puts
calls to_s
. I hope this clears it up for you, if not let me know and I'll elaborate.
Comments
-
fnllc about 2 years
I'm on Rails 2.3 and I'm trying to convert a string that is JSON-formatted to a Rails hash. However, when I use
JSON.parse
I get a JSON string without the delimiters:{"source_id":40007,"object":"86088947610496.1","coursewalk_id":"86088947610477.1","description":"","image_uri":"db\/db-files\/ Image_2011-09-24_14.37.37__0000.jpg","latitude":"38.0113439821061","letter":"","letter_A":"","letter_B":"","letter_C":"","lett er_D":"","letter_E":"","letter_F":"","longitude":"-78.7576854509104","number":"1","mcw_id":71}
Results of
JSON.parse
:number1letter_Bcoursewalk_id86088947610477.1letter_Clatitude38.0113439821061letter_Dletter_Eletter_Fmcw_id71longitude-78.75768 54509104letterdescriptionobject86088947610496.1source_id40007letter_Aimage_uridb/db-files/Image_2011-09-24_14.37.37__0000.jpg
Code:
puts string_to_parse fence_parsed = JSON.parse(string_to_parse) puts fence_parsed
Any ideas?
Thanks, Nick
-
fnllc over 12 yearsThat's what it was! Can't believe how many hours I wasted. Thanks!