Num*_*ers 19 ruby hash serialization json ruby-on-rails
我有一个哈希:
my_hash = {"bob.johnson@example.com"=>{"first"=>"Bob", "last"=>"Johnson"}, "lisa.dell@example.com"=>{"first"=>"Lisa", "last"=>"Dell"}}
Run Code Online (Sandbox Code Playgroud)
当我尝试将其序列化时,my_hash.to_json这就是我得到的:
"{\"bob.johnson@example.com\":{\"first\":\"Bob\",\"last\":\"Johnson\"},\"lisa.dell@example.com\":{\"first\":\"Lisa\",\"last\":\"Dell\"}}"
Run Code Online (Sandbox Code Playgroud)
如何在不获取转义字符的情况下将Hash转换为JSON格式?
Mar*_*pka 51
这些转义字符"在Ruby String(您的my_hash.to_json输出)中转义.如果你这样做
puts my_hash.to_json
Run Code Online (Sandbox Code Playgroud)
你会看到实际上这些转义字符没有添加到输出字符串中.
| 归档时间: |
|
| 查看次数: |
17045 次 |
| 最近记录: |