- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我发现在 Opera 11.50 上的表达式
JSON.stringify(2)
返回一个对象
typeof
返回“string”
constructor.name
是 String
charCodeAt(0)
为 50长度
为1但是还是
alert(JSON.stringify(2) == "2")
在 Opera 中显示“false”(使用 ===
也会发生同样的情况)。
这是一个错误还是什么?
我发现使其比较等于“2”的唯一方法是调用.substr(0)
(例如,即使添加空字符串仍然比较不同)。
最佳答案
这看起来绝对是一个错误。
来自 ECMAScript 5.1 规范:
Conforming implementations of JSON.parse and JSON.stringify must support the exact interchange format described in this specification without any deletions or extensions to the format. This differs from RFC 4627 which permits a JSON parser to accept non-JSON forms and extensions.
还有:
JSON.stringify produces a String that conforms to the following JSON grammar. JSON.parse accepts a String that conforms to the JSON grammar
它可能以某种方式将字符串包装在“JSONText”类型对象中,该对象仍然具有 typeof
的 string
但这看起来很奇怪。
我肯定认为在这种情况下以下实现是正确的:
JSON.stringify(2) == "2" && JSON.stringify(2) === "2" && JSON.stringify(2) == 2 && JSON.stringify(2) !== 2;
true
根据@6502(参见评论),这是true
:
Chrome ;火狐浏览器; IE9; iPad Safari; OSX Safari; N1 Android 浏览器
ECMAScript 5.1 规范文档:http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
关于javascript - JSON.stringify(2) == "2"可能返回 false 是否正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7058148/
我从 https://github.com/douglascrockford/JSON-js/blob/master/json2.js 下载了 JSON2.js并且它没有 JSON2.stringif
我制作了一个 Stringify 协议(protocol),将实现该协议(protocol)的类型转换为字符串。 protocol Stringify { func stringify() -
在我的Reaction Native 0.70应用程序中有一些不可序列化的东西,它在上下文API中传递,以使它们可用于以下组件。以下是它的代码:。在可能需要检索不可序列化值的组件中:。但是,它在组件中
MISRA 标准不允许在宏定义中使用字符串化运算符在不使用 # 运算符的情况下实现相同概念的替代方法是什么? 最佳答案 实际上并没有任何直接的替代方案——只有变通办法。此建议规则与建议不要使用类似函数
MISRA 标准不允许在宏定义中使用字符串化运算符在不使用 # 运算符的情况下实现相同概念的替代方法是什么? 最佳答案 实际上并没有任何直接的替代方案——只有变通办法。此建议规则与建议不要使用类似函数
前言 JSON是一种轻量级数据格式,可以方便地表示复杂数据结构。JSON对象有两个方法:stringify()和parse()。在简单的情况下,这两个方法分别可以将JavaScript序列化
...使用 JSON2.js 和 JQUERY 正如您从第一张图片中看到的,对象属性 customerReport.Title 有撇号。在代码中你可以看到我正在调用 JSON.stringify()
我目前正在调查为什么 JSON.stringify() 没有正确解析我的对象。这是我试图解析为 JSON 字符串的对象: var data = [{ name: string, act
问题 大家好,有人可以帮我解决这个复杂的问题吗? :我正在使用 Spring boot v2.0.5 和 React.js v15.6.2、ReactDom v15.6.2、React Bootstr
我正在使用 Knockout.js 和 ASP.NET web ApiController 完成一个新项目。我看到的许多示例在将数据发布到服务器之前执行一些手动 JSON 序列化。此外,请求内容类型同
此宏在调用时编译: macro_rules! remote_optional { ($remote:ident with=$def:ident $def_str:expr) => {
我有一个返回对象,需要打印一些属性,但 JSON.stringify 无法识别一些属性。 例如: Object = {"Date":"Mon, 22 Jun 2015 10:56:50 GMT","C
JSON.stringify( ) 是否等同于序列化或有效序列化,或者它只是实现的必要步骤序列化? 换句话说,JSON.stringify( ) 是否足够但不需要序列化?还是必要但不充分?还是 Jav
JSON.stringify是我们经常用到的的一个方法,它主要作用是将 JavaScript 值和对象转换为字符串。如: JSON.stringify({ foo: "bar&
GCC 似乎总是在源代码中用空格扩展制表符。它保留表达式内部的空间。标准对此有何规定? 例如,c 会是什么?此示例中包含( 表示源代码文件中的乱码 \t 字符)。 #define X(a) #a co
根据this答案,JSON.parse() 的时间复杂度是 O(n) . 这是否适用于 JSON.stringify() ?似乎没有任何地方记录这一点。 最佳答案 它应该是 O(n),但是 n是被字符
connection.query( 'SELECT DeskName FROM desks WHERE stat = ?',["Booked"], function(err, rows){ if(
我们正在根据一种简单的模板格式构建动态 JSON 有效负载,该格式指示我们的有效负载应产生多少级别,例如"level1.level2"> 将产生: { "level1": [ {
我对 Node.js 和传递 JSON 数据相当陌生,但是有人可以让我深入了解为什么我不需要在其中执行 JSON.stringify 。 module.exports.getBusinessOffer
我有一个简单的 JavaScript 对象,其中包含一些设备信息,包括最后已知的地理位置(仅经度和纬度)。我正在使用 JSON.stringify 将此对象转换为 JSON,但我拥有的一个不是 boo
我是一名优秀的程序员,十分优秀!