我有一个杂烩:
my_hash={”bob。[email protected]丽萨,“{”第一个“=”鲍勃“,”最后一个“=”约翰逊“}”。[email protected]“=>;{”第一个“=>;“丽莎”,“最后一个”=>;“戴尔”}”
当我尝试用my_hash.to_json
对其进行序列化时,我得到的结果是:
“{\”鲍勃。[email protected]\“:{first\”:“Bob\”,“last\”:“Johnson\”},\“lisa”。[email protected]\“:{\'first\':\'Lisa\',\'last\':\'Dell\'}”
如何在不获取转义字符的情况下将哈希转换为JSON格式
这些转义字符在Ruby字符串中转义
“
(您的my\u hash.to\u json
输出)
将我的\u hash.to \u json
您将看到,实际上这些转义字符并没有添加到输出字符串中