问题标签 [jsonserializer]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
javascript - JSON Stringify 和 Parse 函数提供不一致的结果
可能重复:
JSON.stringify() 怪异
好的,所以我使用了各种 JSON 方法(字符串化和解析),但最近遇到了一个页面,它们的行为不正确。我正在使用 Chrome 版本 23.0.1271.91 m
例如,如果我将以下内容放入控制台:
我通常会得到这个:
但特别是在一页上,我得到以下内容:
其中 parsed 是一个值为 [{"color": "red"}, {"name": "ryan"}] 的字符串,而不是具有这些值/属性的对象。
我只是不确定如何解决这个问题。显然,序列化中出了点问题。这是在我无法控制其他脚本正在运行的环境中(它是一个插件),因此该解决方案不能真正涉及禁用可能导致干扰的其他脚本,因为我可能不知道它们和这可能会导致其他问题。