JSON.stringfy
1419 단어 js 함수
if (!window.JSON) {
window.JSON = {
stringify: function (vContent) {
if (vContent instanceof Object) {
var sOutput = '';
if (vContent.constructor === Array) {
for (var nId = 0; nId < vContent.length; nId++) {
sOutput += this.stringify(vContent[nId]) + ',';
}
return '[' + sOutput.substr(0, sOutput.length - 1) + ']';
}
if (vContent.toString !== Object.prototype.toString) {
return '"' + vContent.toString().replace(/"/g, '\\$&') + '"';
}
for (var sProp in vContent) {
if (vContent[sProp]) {
sOutput += '"' + sProp.replace(/"/g, '\\$&') + '":' + this.stringify(vContent[sProp]) + ',';
}
}
return '{' + sOutput.substr(0, sOutput.length - 1) + '}';
}
return typeof vContent === 'string' ? '"' + vContent.replace(/"/g, '\\$&') + '"' : String(vContent);
}
};
}