为什么内容类型标头用于json? "应用/ JSON; charset = utf-8"或“application / json”? [英] Why content type header to use for json? "application/json; charset=utf-8 " or "application/json"?
问题描述
看起来像json默认编码是UTF-8
Spring mvc默认返回application / json; charset = utf-8并且很难改变它。
looks like the json default encoding is UTF-8 Spring mvc returns "application/json; charset=utf-8 " by default and pretty hard to change it.
推荐答案
根据 RFC 4627
JSON文本应以Unicode编码。默认编码是UTF-8。
JSON text SHALL be encoded in Unicode. The default encoding is UTF-8.
继续描述不同的UTF- *编码将如何检测,这表明没有其他编码支持。
It goes on to describe how the different UTF-* encoding are to be detecting, suggesting that no other encodings are supported.
SHALL代表绝对要求(参见 RFC 2119 )。
"SHALL" represents an absolute requirement here (see RFC 2119).
并且没有理由使用带有JSON的非UTF编码(因为任何可以处理JSON的东西都可以绝对处理UTF-8)。
And there really is no reason to use a non-UTF encoding with JSON (as anything that can handle JSON can definitely handle UTF-8).
这篇关于为什么内容类型标头用于json? "应用/ JSON; charset = utf-8"或“application / json”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!