有些浏览器为什么似乎需要对JSON数据使用UTF-8字符集显示? [英] Why do some browsers seem to require a UTF-8 charset on JSON data for display?

查看:130
本文介绍了有些浏览器为什么似乎需要对JSON数据使用UTF-8字符集显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

于是,我看到了一个:<一href=\"http://stackoverflow.com/questions/477816/what-is-the-correct-json-content-type/477819#477819\">What是正确的JSON内容类型? - 应用程序/ JSON 以及<一个href=\"http://stackoverflow.com/questions/19814908/why-content-type-header-to-use-for-json-application-json-charset-utf-8-or\">Why内容类型头使用JSON? &QUOT;应用/ JSON的;字符集= UTF-8英寸或QUOT;应用/ JSON&QUOT;?和<一个href=\"http://stackoverflow.com/questions/9254891/what-does-content-type-application-json-charset-utf-8-really-mean/9254967#9254967\">What的确&QUOT;内容类型:应用程序/ JSON的;字符集= UTF-8英寸究竟意味着什么?

So I see the A: What is the correct JSON content type? - application/json as well as Why content type header to use for json? "application/json; charset=utf-8 " or "application/json"? and What does "Content-type: application/json; charset=utf-8" really mean?

如前所述那里, RFC 7159 说,对于JSON的默认编码是utf-8,指出:

As noted there, RFC 7159 says that the default encoding for JSON is utf-8 and notes that:

没有字符集参数对该登记所定义。
        增加一个真正对符合收件人没有影响。

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

然而,在现实中,一些浏览器至少(Safari和Firefox)似乎除非charset参数添加的申请自动检测改为JSON数据(见的这张票起诉我以及相关的SO问题上面链接)。所以我不能说任何一种方式我没有测试过XMLHTT prequest实现。我认为他们处理应用程序/ JSON 正常。

However, in reality, some browsers at least (Safari and Firefox) seem to apply "auto-detect" to the JSON data unless a charset parameter is added (see this ticket filed against me and also the related SO question linked above). I haven't tested XMLHTTPRequest implementations so I can't say either way. I assume they handle application/json properly.

所以我想我的问题是稍有不同 - 在浏览器的显示的,是需要的字符集,因为这些浏览器的内置JSON显示实际上并不符合RFC

So I think my question is slightly different - for display in the browser, is the charset required because these browsers' built-in JSON display is not actually RFC compliant?

推荐答案

有关于这个一个Firefox的错误:的观看时不要兑现字符集JSON #741776说XHR忽略字符集和docview shold也。

There is a Firefox bug on this: "Don't honor charset when viewing JSON" #741776 says that XHR ignores charset and that docview shold also.

这篇关于有些浏览器为什么似乎需要对JSON数据使用UTF-8字符集显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆