JSON 指定“任何 UNICODE 字符”?

发布于 2024-08-31 20:19:10 字数 273 浏览 4 评论 0原文

也许这只是我对unicode的不熟悉,所以如果我错了,请纠正我。

查看 http://json.org/,规范规定字符串可以包含“任何 UNICODE 字符”,但是这让我很困惑。

  • JSON是一种通信格式 正确的?其核心是, 一切都必须转化为 字节。
  • 相比之下,UNICODE 是 逻辑格式并且必须编码为 可以传送的吧?

那么他们的意思是什么?

Maybe this is just my unfamiliarity with unicode, so please correct me if I'm mistaken.

Looking at http://json.org/, the spec says that a string can include "any UNICODE character", but this confuses me.

  • JSON is a communication format
    correct? At the core of it,
    everything must translate down to
    bytes.
  • In contrast, UNICODE is a
    logical format and must be encoded to
    be able to transmit it, right?

So what did they mean there?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甜心 2024-09-07 20:19:10

来自 RFC

3.  Encoding

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

   Since the first two characters of a JSON text will always be ASCII
   characters [RFC0020], it is possible to determine whether an octet
   stream is UTF-8, UTF-16 (BE or LE), or UTF-32 (BE or LE) by looking
   at the pattern of nulls in the first four octets.

           00 00 00 xx  UTF-32BE
           00 xx 00 xx  UTF-16BE
           xx 00 00 00  UTF-32LE
           xx 00 xx 00  UTF-16LE
           xx xx xx xx  UTF-8

From the RFC:

3.  Encoding

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

   Since the first two characters of a JSON text will always be ASCII
   characters [RFC0020], it is possible to determine whether an octet
   stream is UTF-8, UTF-16 (BE or LE), or UTF-32 (BE or LE) by looking
   at the pattern of nulls in the first four octets.

           00 00 00 xx  UTF-32BE
           00 xx 00 xx  UTF-16BE
           xx 00 00 00  UTF-32LE
           xx 00 xx 00  UTF-16LE
           xx xx xx xx  UTF-8
淡墨 2024-09-07 20:19:10

JSON 是一种序列化格式,可以包含 UNICODE 字符。此 unicode 字符串的字节表示通常通过线路发送,通常通过 HTTP 协议发送,该协议使用 HTTP 标头来指定客户端的编码(UTF-8)。

JSON is a serialization format which can include UNICODE characters. The byte representation of this unicode string is usually sent over the wire, normally through the HTTP protocol which uses HTTP headers to specify the encoding to the client which is UTF-8.

好菇凉咱不稀罕他 2024-09-07 20:19:10

您是对的,所有内容都必须转换为字节,并且通常通过 UTF(Unicode 转换格式)进行。 JSON RFC 在 第 3 节中解释了如何判断 UTF 是什么用过的。

You're correct that everything must translate into bytes, and usually that usually occurs through a UTF (Unicode Transformation Format). The JSON RFC explains in section 3 how to tell what UTF is being used.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文