开发者

Does encoding matter for JSON?

开发者 https://www.devze.com 2023-01-30 09:53 出处:网络
Does JSON only support Unicode?开发者_如何转开发 It doesn\'t seem like encoding matters if this is the case. Won\'t all JSON then be unicode, and the Charset just a matter of storage?From the RFC, &qu

Does JSON only support Unicode?开发者_如何转开发 It doesn't seem like encoding matters if this is the case. Won't all JSON then be unicode, and the Charset just a matter of storage?


From the RFC, "JSON text SHALL be encoded in Unicode." Unicode is really a character set, not an encoding, though. It also says the "default encoding is UTF-8." The same section explains how to distinguish between UTF-32BE, UTF-16BE, UTF-32LE, UTF-16LE, and UTF-8 based on the pattern of nulls.

In summary, use UTF-8 unless you have a strong reason to do otherwise. However, you can use a different Unicode encoding.


Encoding would matter when you read or parse the JSON string to be sent in the response. So response encoding would come into play When reading a JSON data from request, you would need to make sure you have encoding set for that case as well.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号