1
|
|
|
/** |
2
|
|
|
* jQuery JSON Plugin |
3
|
|
|
* version: 2.3 (2011-09-17) |
4
|
|
|
* |
5
|
|
|
* This document is licensed as free software under the terms of the |
6
|
|
|
* MIT License: http://www.opensource.org/licenses/mit-license.php |
7
|
|
|
* |
8
|
|
|
* Brantley Harris wrote this plugin. It is based somewhat on the JSON.org |
9
|
|
|
* website's http://www.json.org/json2.js, which proclaims: |
10
|
|
|
* "NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.", a sentiment that |
11
|
|
|
* I uphold. |
12
|
|
|
* |
13
|
|
|
* It is also influenced heavily by MochiKit's serializeJSON, which is |
14
|
|
|
* copyrighted 2005 by Bob Ippolito. |
15
|
|
|
*/ |
16
|
|
|
(function($){var escapeable=/["\\\x00-\x1f\x7f-\x9f]/g,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'};$.toJSON=typeof JSON==='object'&&JSON.stringify?JSON.stringify:function(o){if(o===null){return'null';} |
17
|
|
|
var type=typeof o;if(type==='undefined'){return undefined;} |
18
|
|
|
if(type==='number'||type==='boolean'){return''+o;} |
19
|
|
|
if(type==='string'){return $.quoteString(o);} |
20
|
|
|
if(type==='object'){if(typeof o.toJSON==='function'){return $.toJSON(o.toJSON());} |
21
|
|
|
if(o.constructor===Date){var month=o.getUTCMonth()+1,day=o.getUTCDate(),year=o.getUTCFullYear(),hours=o.getUTCHours(),minutes=o.getUTCMinutes(),seconds=o.getUTCSeconds(),milli=o.getUTCMilliseconds();if(month<10){month='0'+month;} |
22
|
|
|
if(day<10){day='0'+day;} |
23
|
|
|
if(hours<10){hours='0'+hours;} |
24
|
|
|
if(minutes<10){minutes='0'+minutes;} |
25
|
|
|
if(seconds<10){seconds='0'+seconds;} |
26
|
|
|
if(milli<100){milli='0'+milli;} |
27
|
|
|
if(milli<10){milli='0'+milli;} |
28
|
|
|
return'"'+year+'-'+month+'-'+day+'T'+ |
29
|
|
|
hours+':'+minutes+':'+seconds+'.'+milli+'Z"';} |
30
|
|
|
if(o.constructor===Array){var ret=[];for(var i=0;i<o.length;i++){ret.push($.toJSON(o[i])||'null');} |
31
|
|
|
return'['+ret.join(',')+']';} |
32
|
|
|
var name,val,pairs=[];for(var k in o){type=typeof k;if(type==='number'){name='"'+k+'"';}else if(type==='string'){name=$.quoteString(k);}else{continue;} |
|
|
|
|
33
|
|
|
type=typeof o[k];if(type==='function'||type==='undefined'){continue;} |
34
|
|
|
val=$.toJSON(o[k]);pairs.push(name+':'+val);} |
35
|
|
|
return'{'+pairs.join(',')+'}';}};$.evalJSON=typeof JSON==='object'&&JSON.parse?JSON.parse:function(src){return eval('('+src+')');};$.secureEvalJSON=typeof JSON==='object'&&JSON.parse?JSON.parse:function(src){var filtered=src.replace(/\\["\\\/bfnrtu]/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,'');if(/^[\],:{}\s]*$/.test(filtered)){return eval('('+src+')');}else{throw new SyntaxError('Error parsing JSON, source is not valid.');}};$.quoteString=function(string){if(string.match(escapeable)){return'"'+string.replace(escapeable,function(a){var c=meta[a];if(typeof c==='string'){return c;} |
|
|
|
|
36
|
|
|
c=a.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+(c%16).toString(16);})+'"';} |
37
|
|
|
return'"'+string+'"';};})(jQuery); |