5 This file adds these methods to JavaScript:
9 This method produces a JSON text from an object. The
10 object must not contain any cyclical references.
14 This method produces a JSON text from an array. The
15 array must not contain any cyclical references.
19 This method parses a JSON text to produce an object or
20 array. It will return false if there is an error.
34 var a = ['['], b, f, i, l = x.length, v;
35 for (i = 0; i < l; i += 1) {
40 if (typeof v == 'string') {
52 'boolean': function (x) {
55 'null': function (x) {
58 number: function (x) {
59 return isFinite(x) ? String(x) : 'null';
61 object: function (x) {
63 if (x instanceof Array) {
66 var a = ['{'], b, f, i, v;
72 if (typeof v == 'string') {
76 a.push(s.string(i), ':', v);
86 string: function (x) {
87 if (/["\\\x00-\x1f]/.test(x)) {
88 x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) {
95 Math.floor(c / 16).toString(16) +
96 (c % 16).toString(16);
103 Object.toJSON = function(obj) {
104 return s.object(obj);
108 String.prototype.parseJSON = function () {
110 return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
111 this.replace(/"(\\.|[^"\\])*"/g, ''))) &&
112 eval('(' + this + ')');