What content type header to use for JSON? “application/json; charset=utf-8 ” or “application/json”?

前端 未结 2 720
忘了有多久
忘了有多久 2020-12-14 19:23

It seems that the JSON default encoding is UTF-8 and Spring MVC returns application/json; charset=utf-8 by default, which is hard to change.

相关标签:
2条回答
  • 2020-12-14 20:08

    Returning a charset parameter on application/json is incorrect, as that media type does not define a charset parametert. See https://greenbytes.de/tech/webdav/rfc8259.html#rfc.section.11, last sentence:

    Note: No "charset" parameter is defined for this registration. Adding one really has no effect on compliant recipients.

    0 讨论(0)
  • 2020-12-14 20:25

    According to RFC 4627

    JSON text SHALL be encoded in Unicode. The default encoding is UTF-8.

    It goes on to describe how the different UTF-* encoding are to be detecting, suggesting that no other encodings are supported.

    "SHALL" represents an absolute requirement here (see RFC 2119).

    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).

    0 讨论(0)
提交回复
热议问题