This shouldn't matter to you. Basically you are seeing the methods added to Array.prototype by MooTools. The fact that your 'dump' function includes these properties is inconsequential. You can still iterate over the array as normal. The fact is, you WANT these properties to be there (that's why you use MooTools!). But you can still loop over your array as normal.
On Thu, Jan 15, 2009 at 2:27 AM, Philipp S. (via Nabble) < [email protected]<ml-user%[email protected]> > wrote: > Hello there! > > I'm currently working on a sortableTable Script that automatically loads a > JSON-File. The JSON-String is the following: > > var object = eval('({"set":{"1":[1,2,3],"2":[4,5,6]}})'); > > When I use the Mootools Request.JSON Class to load and parse it, the Object > looks like this (I used the "dump"-function to display): > > > 'set' ... > '1' ... > '0' => "1" > '1' => "2" > '2' => "3" > '$family' ... > 'name' => "array" > 'each' => "function forEach() { > [native code] > }" > 'clean' => "function () { > return this.filter($defined); > }" > 'associate' => "function (keys) { > var obj = {}, length = Math.min(this.length, keys.length); > for (var i = 0; i < length; i++) { > obj[keys[i]] = this[i]; > } > return obj; > }" > 'link' => "function (object) { > var result = {}; > for (var i = 0, l = this.length; i < l; i++) { > for (var key in object) { > if (object[key](this[i])) { > result[key] = this[i]; > delete object[key]; > break; > } > } > } > return result; > }" > 'contains' => "function (item, from) { > return this.indexOf(item, from) != -1; > }" > 'extend' => "function (array) { > for (var i = 0, j = array.length; i < j; i++) { > this.push(array[i]); > } > return this; > }" > 'getLast' => "function () { > return this.length ? this[this.length - 1] : null; > }" > 'getRandom' => "function () { > return this.length ? this[$random(0, this.length - 1)] : null; > }" > 'include' => "function (item) { > if (!this.contains(item)) { > this.push(item); > } > return this; > }" > 'combine' => "function (array) { > for (var i = 0, l = array.length; i < l; i++) { > this.include(array[i]); > } > return this; > }" > 'erase' => "function (item) { > for (var i = this.length; i--; i) { > if (this[i] === item) { > this.splice(i, 1); > } > } > return this; > }" > 'empty' => "function () { > this.length = 0; > return this; > }" > 'flatten' => "function () { > var array = []; > for (var i = 0, l = this.length; i < l; i++) { > var type = $type(this[i]); > if (!type) { > continue; > } > array = array.concat((type == "array" || type == "collection" || > type == "arguments") ? Array.flatten(this[i]) : this[i]); > } > return array; > }" > 'hexToRgb' => "function (array) { > if (this.length != 3) { > return null; > } > var rgb = this.map(function (value) {if (value.length == 1) {value += > value;}return value.toInt(16);}); > return array ? rgb : "rgb(" + rgb + ")"; > }" > 'rgbToHex' => "function (array) { > if (this.length < 3) { > return null; > } > if (this.length == 4 && this[3] == 0 && !array) { > return "transparent"; > } > var hex = []; > for (var i = 0; i < 3; i++) { > var bit = (this[i] - 0).toString(16); > hex.push((bit.length == 1) ? "0" + bit : bit); > } > return array ? hex : "#" + hex.join(""); > }" > 'toJSON' => "function () { > return JSON.encode(this); > }" > 'rgbToHsb' => "function () { > var red = this[0], green = this[1], blue = this[2]; > var hue, saturation, brightness; > var max = Math.max(red, green, blue), min = Math.min(red, green, blue); > > var delta = max - min; > brightness = max / 255; > saturation = (max != 0) ? delta / max : 0; > if (saturation == 0) { > hue = 0; > } else { > var rr = (max - red) / delta; > var gr = (max - green) / delta; > var br = (max - blue) / delta; > if (red == max) { > hue = br - gr; > } else if (green == max) { > hue = 2 + rr - br; > } else { > hue = 4 + gr - rr; > } > hue /= 6; > if (hue < 0) { > hue++; > } > } > return [Math.round(hue * 360), Math.round(saturation * 100), > Math.round(brightness * 100)]; > }" > 'hsbToRgb' => "function () { > var br = Math.round(this[2] / 100 * 255); > if (this[1] == 0) { > return [br, br, br]; > } else { > var hue = this[0] % 360; > var f = hue % 60; > var p = Math.round((this[2] * (100 - this[1])) / 10000 * 255); > var q = Math.round((this[2] * (6000 - this[1] * f)) / 600000 * > 255); > var t = Math.round((this[2] * (6000 - this[1] * (60 - f))) / 600000 > * 255); > switch (Math.floor(hue / 60)) { > case 0: > return [br, t, p]; > case 1: > return [q, br, p]; > case 2: > return [p, br, t]; > case 3: > return [p, q, br]; > case 4: > return [t, p, br]; > case 5: > return [br, p, q]; > default:; > } > } > return false; > }" > '2' ... > '0' => "4" > '1' => "5" > '2' => "6" > '$family' ... > 'name' => "array" > 'each' => "function forEach() { > [native code] > }" > 'clean' => "function () { > return this.filter($defined); > }" > 'associate' => "function (keys) { > var obj = {}, length = Math.min(this.length, keys.length); > for (var i = 0; i < length; i++) { > obj[keys[i]] = this[i]; > } > return obj; > }" > 'link' => "function (object) { > var result = {}; > for (var i = 0, l = this.length; i < l; i++) { > for (var key in object) { > if (object[key](this[i])) { > result[key] = this[i]; > delete object[key]; > break; > } > } > } > return result; > }" > 'contains' => "function (item, from) { > return this.indexOf(item, from) != -1; > }" > 'extend' => "function (array) { > for (var i = 0, j = array.length; i < j; i++) { > this.push(array[i]); > } > return this; > }" > 'getLast' => "function () { > return this.length ? this[this.length - 1] : null; > }" > 'getRandom' => "function () { > return this.length ? this[$random(0, this.length - 1)] : null; > }" > 'include' => "function (item) { > if (!this.contains(item)) { > this.push(item); > } > return this; > }" > 'combine' => "function (array) { > for (var i = 0, l = array.length; i < l; i++) { > this.include(array[i]); > } > return this; > }" > 'erase' => "function (item) { > for (var i = this.length; i--; i) { > if (this[i] === item) { > this.splice(i, 1); > } > } > return this; > }" > 'empty' => "function () { > this.length = 0; > return this; > }" > 'flatten' => "function () { > var array = []; > for (var i = 0, l = this.length; i < l; i++) { > var type = $type(this[i]); > if (!type) { > continue; > } > array = array.concat((type == "array" || type == "collection" || > type == "arguments") ? Array.flatten(this[i]) : this[i]); > } > return array; > }" > 'hexToRgb' => "function (array) { > if (this.length != 3) { > return null; > } > var rgb = this.map(function (value) {if (value.length == 1) {value += > value;}return value.toInt(16);}); > return array ? rgb : "rgb(" + rgb + ")"; > }" > 'rgbToHex' => "function (array) { > if (this.length < 3) { > return null; > } > if (this.length == 4 && this[3] == 0 && !array) { > return "transparent"; > } > var hex = []; > for (var i = 0; i < 3; i++) { > var bit = (this[i] - 0).toString(16); > hex.push((bit.length == 1) ? "0" + bit : bit); > } > return array ? hex : "#" + hex.join(""); > }" > 'toJSON' => "function () { > return JSON.encode(this); > }" > 'rgbToHsb' => "function () { > var red = this[0], green = this[1], blue = this[2]; > var hue, saturation, brightness; > var max = Math.max(red, green, blue), min = Math.min(red, green, blue); > > var delta = max - min; > brightness = max / 255; > saturation = (max != 0) ? delta / max : 0; > if (saturation == 0) { > hue = 0; > } else { > var rr = (max - red) / delta; > var gr = (max - green) / delta; > var br = (max - blue) / delta; > if (red == max) { > hue = br - gr; > } else if (green == max) { > hue = 2 + rr - br; > } else { > hue = 4 + gr - rr; > } > hue /= 6; > if (hue < 0) { > hue++; > } > } > return [Math.round(hue * 360), Math.round(saturation * 100), > Math.round(brightness * 100)]; > }" > 'hsbToRgb' => "function () { > var br = Math.round(this[2] / 100 * 255); > if (this[1] == 0) { > return [br, br, br]; > } else { > var hue = this[0] % 360; > var f = hue % 60; > var p = Math.round((this[2] * (100 - this[1])) / 10000 * 255); > var q = Math.round((this[2] * (6000 - this[1] * f)) / 600000 * > 255); > var t = Math.round((this[2] * (6000 - this[1] * (60 - f))) / 600000 > * 255); > switch (Math.floor(hue / 60)) { > case 0: > return [br, t, p]; > case 1: > return [q, br, p]; > case 2: > return [p, br, t]; > case 3: > return [p, q, br]; > case 4: > return [t, p, br]; > case 5: > return [br, p, q]; > default:; > } > } > return false; > }" > > > As you can see, some "Native Code" is added to the Object when the arrays > are parsed completely. I made some experiments with that, and came to the > conclusion, that it is the eval() function in the mootools core which is > responsible for the changes. (I made a alert before, and after the line. > Before eval() is used, my JSON-String is correct). I also tried to use > native JavaScript to parse the JSON without using mootools in any way, but > still with the mootools.js included. I still get this error. Only if I > delete the mootools.js inclusion, everything works out fine. > > Looks like mootools changes the behaviour of eval(). Any Ideas? > > ------------------------------ > View message @ > http://n2.nabble.com/JSON-Object-is-changed-when-parsed-tp2161732p2161732.html > To start a new topic under MooTools Users, email > [email protected]<ml-node%[email protected]> > To unsubscribe from MooTools Users, click here< (link removed) >. > > > ----- The MooTools Tutorial: http://www.mootorial.com www.mootorial.com Clientcide: http://www.clientcide.com www.clientcide.com -- View this message in context: http://n2.nabble.com/JSON-Object-is-changed-when-parsed-tp2161732p2164032.html Sent from the MooTools Users mailing list archive at Nabble.com.
