web/data/jquery.json.js
changeset 9661 c170ec8a4525
parent 9660 a78efec4cf04
child 9662 f13ae1fea212
equal deleted inserted replaced
9660:a78efec4cf04 9661:c170ec8a4525
     1 (function($){function toIntegersAtLease(n)
       
     2 {return n<10?'0'+n:n;}
       
     3 Date.prototype.toJSON=function(date)
       
     4 {return date.getUTCFullYear()+'-'+
       
     5 toIntegersAtLease(date.getUTCMonth()+1)+'-'+
       
     6 toIntegersAtLease(date.getUTCDate());};var escapeable=/["\\\x00-\x1f\x7f-\x9f]/g;var meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'}
       
     7 $.quoteString=function(string)
       
     8 {if(escapeable.test(string))
       
     9 {return'"'+string.replace(escapeable,function(a)
       
    10 {var c=meta[a];if(typeof c==='string'){return c;}
       
    11 c=a.charCodeAt();return'\\u00'+Math.floor(c/16).toString(16)+(c%16).toString(16);})+'"'}
       
    12 return'"'+string+'"';}
       
    13 $.toJSON=function(o)
       
    14 {var type=typeof(o);if(type=="undefined")
       
    15 return"undefined";else if(type=="number"||type=="boolean")
       
    16 return o+"";else if(o===null)
       
    17 return"null";if(type=="string")
       
    18 {return $.quoteString(o);}
       
    19 if(type=="object"&&typeof o.toJSON=="function")
       
    20 return o.toJSON();if(type!="function"&&typeof(o.length)=="number")
       
    21 {var ret=[];for(var i=0;i<o.length;i++){ret.push($.toJSON(o[i]));}
       
    22 return"["+ret.join(", ")+"]";}
       
    23 if(type=="function"){throw new TypeError("Unable to convert object of type 'function' to json.");}
       
    24 ret=[];for(var k in o){var name;var type=typeof(k);if(type=="number")
       
    25 name='"'+k+'"';else if(type=="string")
       
    26 name=$.quoteString(k);else
       
    27 continue;val=$.toJSON(o[k]);if(typeof(val)!="string"){continue;}
       
    28 ret.push(name+": "+val);}
       
    29 return"{"+ret.join(", ")+"}";}
       
    30 $.evalJSON=function(src)
       
    31 {return eval("("+src+")");}
       
    32 $.secureEvalJSON=function(src)
       
    33 {var filtered=src;filtered=filtered.replace(/\\["\\\/bfnrtu]/g,'@');filtered=filtered.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']');filtered=filtered.replace(/(?:^|:|,)(?:\s*\[)+/g,'');if(/^[\],:{}\s]*$/.test(filtered))
       
    34 return eval("("+src+")");else
       
    35 throw new SyntaxError("Error parsing JSON, source is not valid.");}})(jQuery);