gpt4 book ai didi

json - json.js 和 json2.js 的区别

转载 作者:IT老高 更新时间:2023-10-28 12:42:43 26 4
gpt4 key购买 nike

谁能告诉我这两个 JSON 解析器有什么区别?

https://github.com/douglascrockford/JSON-js/blob/master/json.js
https://github.com/douglascrockford/JSON-js/blob/master/json2.js

我有一个 2007-04-13 的 JSON 文件(它有诸如 parseJSON 之类的方法)。我在任何新版本中都没有看到这些方法。

最佳答案

来自他们的代码:

// Augment the basic prototypes if they have not already been augmented.
// These forms are obsolete. It is recommended that JSON.stringify and
// JSON.parse be used instead.

if (!Object.prototype.toJSONString) {
Object.prototype.toJSONString = function (filter) {
return JSON.stringify(this, filter);
};
Object.prototype.parseJSON = function (filter) {
return JSON.parse(this, filter);
};
}

我猜 parseJSON 已经过时了,因此新版本 (json2) 甚至不再使用它了。但是,如果您的代码使用 parseJSON 很多,您可以在某处添加这段代码以使其再次工作:

    Object.prototype.parseJSON = function (filter) {
return JSON.parse(this, filter);
};

关于json - json.js 和 json2.js 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/552135/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com