JSON parser for any object in the script.
OBS: Need a way to identify methods.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | /**
* jObject.toJson - JSON Parser
*/
Object.prototype.toJson = function() {
var tmp = '{';
/* {"property1":"value1", "property2":"value2"} */
for (i in this) {
if (this[i] != this.toJson) {
tmp = tmp + '"' + i + '":"' + this[i] + '",';
}
}
tmp = tmp.substring(0, (tmp.length - 1)) + '}';
return tmp;
}
|