简体   繁体   English

XML和JSON模式中的UTF-8

[英]UTF-8 in XML and JSON Schema

I'm little bit confusing about utf-8 in XML and JSON Schema 我对XML和JSON模式中的utf-8有点困惑

I have following array 我有以下数组

$array = array(
    array('name'=>'abc', 'text'=>'اسلسصثصض صثصهخه عه☆anton & budi☆' ),
    array('name'=>'xyz', 'text'=>'nice' ),
);

when i convert it to XML it give me this result 当我将其转换为XML时,它会给我这个结果

<?xml version="1.0"?>
<response>
  <item>
    <name>abc</name>
    <text>&#x627;&#x633;&#x644;&#x633;&#x635;&#x62B;&#x635;&#x636; &#x635;&#x62B;&#x635;&#x647;&#x62E;&#x647; &#x639;&#x647;&#x2606;anton '&lt;&amp;&gt;' budi&#x2606;</text>
  </item>
  <item>
    <name>xyz</name>
    <text>nice</text>
  </item>
</response>

Why the result is not like following : 为什么结果不像下面这样:

<?xml version="1.0"?>
<response>
  <item>
    <name>abc</name>
    <text>اسلسصثصض صثصهخه عه☆anton &amp; budi☆</text>
  </item>
  <item>
    <name>xyz</name>
    <text>nice</text>
  </item>
</response>

And When i convert it to JSON it will give me result : 当我将其转换为JSON时,它会给我结果:

[
  {
    "name": "abc",
    "text": "\u0627\u0633\u0644\u0633\u0635\u062b\u0635\u0636 \u0635\u062b\u0635\u0647\u062e\u0647 \u0639\u0647\u2606anton '<&>' budi\u2606"
  },
  {
    "name": "xyz",
    "text": "nice"
  }
]

and why not like this : 为什么不这样:

[
  {
    "name": "abc",
    "text": "اسلسصثصض صثصهخه عه☆anton &amp; budi☆"
  },
  {
    "name": "xyz",
    "text": "nice"
  }
]

is that any way to use utf-8 character inside xml or json ? 有什么办法在xml或json中使用utf-8字符吗? or that's are the standard ? 还是那是标准?

It's probably for the sake of diagnostics and a better likelihood of being transported correctly - systems are generally pretty good at transporting ASCII, but many systems aren't written well when it comes to other encodings. 这可能是出于诊断的目的,也可能是正确传输的可能性更大-系统通常在传输ASCII方面相当不错,但是在涉及其他编码时,许多系统的编写情况并不理想。

It should, of course, be possible to transport the UTF-8 encoded form correctly, but I suspect the encoder you're using is simply being conservative. 当然,应该可以正确地传输UTF-8编码形式,但是我怀疑您使用的编码器只是保守的。 It means you don't need to make sure you get it right at the HTTP level, for example. 例如,这意味着您无需确保在HTTP级别正确使用它。 The main thing is that it will still give the right text overall. 最主要的是,它仍将总体上提供正确的文本。 Is this causing you some actual problem, or were you just surprised by the use of escaping? 这是给您造成一些实际问题,还是您只是对转义的使用感到惊讶?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM