85 json
有人能告诉我两个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
).我没有在任何新版本中看到这些方法.
Luc*_*eis 57
从他们的代码:
// 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);
};
}
Run Code Online (Sandbox Code Playgroud)
我猜parseJSON已经过时,因此新版本(json2)甚至不再使用它了.但是,如果您的代码使用parseJSON
了很多,您可以在某处添加这段代码以使其再次运行:
Object.prototype.parseJSON = function (filter) {
return JSON.parse(this, filter);
};
Run Code Online (Sandbox Code Playgroud)
Vim*_*aju 22
我还注意到json2字符串化的数组与json2007不同.
在json2007中:
var array = [];
array[1] = "apple";
array[2] = "orange";
alert(array.toJSONString()); // Output: ["apple", "orange"].
Run Code Online (Sandbox Code Playgroud)
在json2中:
var array = [];
array[1] = "apple";
array[2] = "orange";
alert(JSON.stringify(array)); // Output: [null, "apple", "orange"].
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
78447 次 |
最近记录: |