DieterHolvoet
1/15/2016 - 1:31 PM

Convert an object string into an object.

Convert an object string into an object.

String.prototype.parseObjectString = function() {
    var s = this.toString(),
        o = {};
    if(s.slice(0, 1) === "{" && s.slice(-1) === "}") {
        s = s.replaceAll('{', '').replaceAll('}', '');

        s = s.split(',');
        for(var i = 0; i < s.length; i++) {
            var t = s[i].split(':');
            t[0] = t[0].trim();
            t[1] = t[1].trim();
            o[t[0]] = parseInt(t[1]);
        }
    }
    return o;
};