Why content type header to use for json? “applicat

2019-02-03 10:46发布

问题:

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.

回答1:

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