JSON encoding wrongly escaped (Rails 3, Ruby 1.9.2)

后端 未结 7 1458
醉梦人生
醉梦人生 2020-12-01 08:14

In my controller, the following works (prints \"oké\")

puts obj.inspect

But this doesn\'t (renders \"ok\\u00e9\")

render :j         


        
7条回答
  •  不思量自难忘°
    2020-12-01 08:36

    That is the correct encoding. JSON doesn't requre Unicode characters to be escaped, but it is common for JSON libraries to produce output which contains only 7-bit ASCII characters, to avoid any potential encoding problems in transit.

    Any JSON interpreter will be able to consume that string and reproduce the original. To see this in action, just type javascript:alert("ok\u00e9") into your browser's location bar.

提交回复
热议问题