Guest User

Untitled

a guest
Feb 12th, 2012
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. var JSON=JSON||{};
  2. (function(){
  3. function f(n){
  4. return n<10?"0"+n:n;
  5. };
  6. if(typeof Date.prototype.toJSON!=="function"){
  7. Date.prototype.toJSON=function(_1){
  8. return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null;
  9. };
  10. String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(_2){
  11. return this.valueOf();
  12. };
  13. }
  14. var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,_3=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,_4,_5,_6={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r","\"":"\\\"","\\":"\\\\"},_7;
  15. function _8(_9){
  16. _3.lastIndex=0;
  17. return _3.test(_9)?"\""+_9.replace(_3,function(a){
  18. var c=_6[a];
  19. return typeof c==="string"?c:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4);
  20. })+"\"":"\""+_9+"\"";
  21. };
  22. function _a(_b,_c){
  23. var i,k,v,_d,_e=_4,_f,_10=_c[_b];
  24. if(_10&&typeof _10==="object"&&typeof _10.toJSON==="function"){
  25. _10=_10.toJSON(_b);
  26. }
  27. if(typeof _7==="function"){
  28. _10=_7.call(_c,_b,_10);
  29. }
  30. switch(typeof _10){
  31. case "string":
  32. return _8(_10);
  33. case "number":
  34. return isFinite(_10)?String(_10):"null";
  35. case "boolean":
  36. case "null":
  37. return String(_10);
  38. case "object":
  39. if(!_10){
  40. return "null";
  41. }
  42. _4+=_5;
  43. _f=[];
  44. if(Object.prototype.toString.apply(_10)==="[object Array]"){
  45. _d=_10.length;
  46. for(i=0;i<_d;i+=1){
  47. _f[i]=_a(i,_10)||"null";
  48. }
  49. v=_f.length===0?"[]":_4?"[\n"+_4+_f.join(",\n"+_4)+"\n"+_e+"]":"["+_f.join(",")+"]";
  50. _4=_e;
  51. return v;
  52. }
  53. if(_7&&typeof _7==="object"){
  54. _d=_7.length;
  55. for(i=0;i<_d;i+=1){
  56. k=_7[i];
  57. if(typeof k==="string"){
  58. v=_a(k,_10);
  59. if(v){
  60. _f.push(_8(k)+(_4?": ":":")+v);
  61. }
  62. }
  63. }
  64. }else{
  65. for(k in _10){
  66. if(Object.hasOwnProperty.call(_10,k)){
  67. v=_a(k,_10);
  68. if(v){
  69. _f.push(_8(k)+(_4?": ":":")+v);
  70. }
  71. }
  72. }
  73. }
  74. v=_f.length===0?"{}":_4?"{\n"+_4+_f.join(",\n"+_4)+"\n"+_e+"}":"{"+_f.join(",")+"}";
  75. _4=_e;
  76. return v;
  77. }
  78. };
  79. if(typeof JSON.stringify!=="function"){
  80. JSON.stringify=function(_11,_12,_13){
  81. var i;
  82. _4="";
  83. _5="";
  84. if(typeof _13==="number"){
  85. for(i=0;i<_13;i+=1){
  86. _5+=" ";
  87. }
  88. }else{
  89. if(typeof _13==="string"){
  90. _5=_13;
  91. }
  92. }
  93. _7=_12;
  94. if(_12&&typeof _12!=="function"&&(typeof _12!=="object"||typeof _12.length!=="number")){
  95. throw new Error("JSON.stringify");
  96. }
  97. return _a("",{"":_11});
  98. };
  99. }
  100. if(typeof JSON.parse!=="function"){
  101. JSON.parse=function(_14,_15){
  102. var j;
  103. function _16(_17,key){
  104. var k,v,_18=_17[key];
  105. if(_18&&typeof _18==="object"){
  106. for(k in _18){
  107. if(Object.hasOwnProperty.call(_18,k)){
  108. v=_16(_18,k);
  109. if(v!==undefined){
  110. _18[k]=v;
  111. }else{
  112. delete _18[k];
  113. }
  114. }
  115. }
  116. }
  117. return _15.call(_17,key,_18);
  118. };
  119. cx.lastIndex=0;
  120. if(cx.test(_14)){
  121. _14=_14.replace(cx,function(a){
  122. return "\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4);
  123. });
  124. }
  125. if(/^[\],:{}\s]*$/.test(_14.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,""))){
  126. j=eval("("+_14+")");
  127. return typeof _15==="function"?_16({"":j},""):j;
  128. }
  129. throw new SyntaxError("JSON.parse");
  130. };
  131. }
  132. }());
Advertisement
Add Comment
Please, Sign In to add comment