JSON encoding wrongly escaped (Rails 3, Ruby 1.9.2)

后端 未结 7 1474
醉梦人生
醉梦人生 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:47

    To set the \uXXXX codes back to utf-8:

    json_string.gsub!(/\\u([0-9a-z]{4})/) {|s| [$1.to_i(16)].pack("U")}
    

提交回复
热议问题