在JSON.stringify差异浏览器之间产生 [英] Differences in JSON.stringify result between browsers

查看:417
本文介绍了在JSON.stringify差异浏览器之间产生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我JSON.stringify()以下的code:

When I JSON.stringify() the following code:

var exampleObject = { "name" : "Žiga Kovač", "kraj" : "Žužemberk"};

我得到浏览器之间的不同的结果。

I get different results between browsers.

IE8和谷歌Chrome回报:

IE8 and Google Chrome return:

{"name":"\u017diga Kova\u010d","kraj":"\u017du\u017eemberk"}

虽然Firefox和Opera的回报:

While Firefox and Opera return:

{"name":"Žiga Kovač","kraj":"Žužemberk"}

我使用所有的浏览器4浏览器的本地JSON实现。如果我取消定义本地JSON执行,并与json.org的替换它,然后所有的浏览器返回:

I am using the browser's native JSON implementation in all 4 browsers. If I undefine the native JSON implementation and replace it with the one from json.org, then all browsers return:

{"name":"Žiga Kovač","kraj":"Žužemberk"}

这是怎么回事,它的结果是正确的,是有可能使所有浏览器返回:

Why is this happening, which result is correct and is it possible to make that all browsers return:

{"name":"\u017diga Kova\u010d","kraj":"\u017du\u017eemberk"}

推荐答案

这两个重presentations绝对是等价的。

These two representations are absolutely equivalent.

该人使用的Uni code转义序列(为\\ uXXXX )重新present一个统一code字符,另一个使用一个实际的统一code字符。 json.org 一个字符串的定义是:

The one uses Unicode escape sequences (\uxxxx) to represent a Unicode character, the other uses an actual Unicode character. json.org defines a string as:


string
    - ""
    - "chars"
chars
    - char
    - char chars
char
    - any Unicode character except " or \ or control characters
    - one of: \" \\ \/ \b \f \n \r \t
    - \u four-hex-digits

有在字符串没有区别自己,只有自己重新presentation。这是当你使用同样的事情HTML确实&放大器;复制; &放大器;#169; ©重新present的版权标志。

There is no difference in the strings themselves, only in their representation. This is the same thing HTML does when you use ©, © or © to represent the copyright sign.

这篇关于在JSON.stringify差异浏览器之间产生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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