JSON字符串到rails hash

use*_*194 5 string hash parsing json ruby-on-rails

我在Rails 2.3上,我正在尝试将JSON格式的字符串转换为Rails哈希.但是,当我使用时,JSON.parse我得到一个没有分隔符的JSON字符串:

{"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}
Run Code Online (Sandbox Code Playgroud)

结果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
Run Code Online (Sandbox Code Playgroud)

码:

puts string_to_parse
fence_parsed = JSON.parse(string_to_parse)
puts fence_parsed
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

谢谢,尼克

bri*_*ker 5

那只是因为你正在使用"推杆".如果你只是打字fence_parsed,或者p fence_parsed你会得到你想要的东西.puts电话to_s.我希望这能为你清除它,如果不让我知道,我会详细说明.