最新Json.js文件下载

2012-10-10更新:修正了和jquery序列化对象为键值对的循环调用冲突问题,具体参考:json.js与jquery冲突too much recursion/Stack Overflow。实际上说应该主要bug部分是json.js,因为即使没有导入jquery,当调用window.toJSONString时就会出现循环递归调用window.toJSONString方法导致堆栈溢出。

  最新Json.js文件下载,json.js将JavaScript对象转换成字符串或者将json格式的字符创转换为json对象。

使用说明
json.js 2007-08-05

Public Domain

This file adds these methods to JavaScript:

array.toJSONString()
boolean.toJSONString()
date.toJSONString()
number.toJSONString()
object.toJSONString()
string.toJSONString()
These methods produce a JSON text from a JavaScript value.
It must not contain any cyclical references. Illegal values
will be excluded.

The default conversion for dates is to an ISO string. You can
add a toJSONString method to any date object to get a different
representation.

string.parseJSON(filter)
This method parses a JSON text to produce an object or
array. It can throw a SyntaxError exception.

The optional filter parameter is a function which can filter and
transform the results. It receives each of the keys and values, and
its return value is used instead of the original value. If it
returns what it received, then structure is not modified. If it
returns undefined then the member is deleted.

Example:

// Parse the text. If a key contains the string 'date' then
// convert the value to a date.

myData = text.parseJSON(function (key, value) {
return key.indexOf('date') >= 0 ? new Date(value) : value;
});

It is expected that these methods will formally become part of the
JavaScript Programming Language in the Fourth Edition of the
ECMAScript standard in 2008.

This file will break programs with improper for..in loops. See
http://yuiblog.com/blog/2006/09/26/for-in-intrigue/

This is a reference implementation. You are free to copy, modify, or
redistribute.

Use your own copy. It is extremely unwise to load untrusted third party
code into your pages.
*/

/*jslint evil: true */

// Augment the basic prototypes if they have not already been augmented.


阅读(1248)喜欢(2)8.52KB浏览器 点击下载