问题描述
有人可以告诉我2个JSON解析器之间的区别是什么吗?
Can someone tell me what the difference is between the 2 JSON parsers?
https://github.com/douglascrockford/JSON-js/blob/master/json.js
https://github.com/douglascrockford/JSON-js/blob/master /json2.js
我有一个2007年4月13日起的JSON文件(它具有诸如parseJSON
之类的方法).我没有在任何新版本中看到这些方法.
I have a JSON file from 2007-04-13 (It has methods such as parseJSON
). I don't see these methods in any of the new versions.
推荐答案
从他们的代码中获取:
// 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
,则可以将这段代码添加到某个地方以使其再次起作用:
I guess parseJSON is obsolete, therefore the new version (json2) doesn't even use it anymore. However if your code uses parseJSON
a lot you could just add this piece of code somewhere to make it work again:
Object.prototype.parseJSON = function (filter) {
return JSON.parse(this, filter);
};
这篇关于json.js和json2.js之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!