Skip to content

Instantly share code, notes, and snippets.

@daejinseok
Created July 22, 2021 13:07
Show Gist options
  • Save daejinseok/45cdf7710ec0dc83d1459c5c7d54c20c to your computer and use it in GitHub Desktop.
Save daejinseok/45cdf7710ec0dc83d1459c5c7d54c20c to your computer and use it in GitHub Desktop.
대충~~ json stringify 짠거 ie8버전용
//https://gist.github.com/andrew8088/6f53af9579266d5c62c8
function stringify2(obj){
var result = [];
var k
for(k in obj){
if(typeof obj[k] === 'object'){
result.push('"' + k + '":' + stringify2(obj[k]));
} else {
result.push('"' + k + '":' + '"' + obj[k] + '"');
}
}
return "{" + result.join(",") + "}";
}
function stringify(obj){
function arr_str(arr){
var r = [];
var idx;
for(idx in arr){
console.log(arr[idx]);
r.push(stringify2(arr[idx]));
}
return '[' + r.join(',') + ']';
}
var result = [];
var k
for(k in obj){
if(typeof obj[k] === 'object'){
if(obj[k] instanceof Array ){
result.push('"' + k + '":' + arr_str(obj[k]));
} else {
result.push('"' + k + '":' + stringify(obj[k]));
}
} else {
result.push('"' + k + '":' + '"' + obj[k] + '"');
}
}
return "{" + result.join(",") + "}";
}
stringify(du.ajax.res);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment