简体   繁体   English

Rails Json响应编码

[英]Rails Json response encoding

I've a rails controller that respond_to JSON with a wrong encoding. 我有一个rails_ controller,它使用错误的编码来响应JSON。 The site is correctly setup with UTF-8 encoding and the database as well. 该站点使用UTF-8编码和数据库正确设置。 The text in my db is well formatted, but in the JSON response, all special characters are set to \�. 我的数据库中的文本格式正确,但在JSON响应中,所有特殊字符都设置为\\ ufffd。 How can I solve the problem? 我该如何解决这个问题?

Everyone running on Ruby 1.9.x and using MySQL, should use the mysql2 gem. 在Ruby 1.9.x上运行并使用MySQL的每个人都应该使用mysql2 gem。 It forces the use of UTF-8 and converts to/from UTF-8 automatically when needed. 它强制使用UTF-8并在需要时自动转换为UTF-8。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM