Created
July 22, 2021 13:07
-
-
Save daejinseok/45cdf7710ec0dc83d1459c5c7d54c20c to your computer and use it in GitHub Desktop.
대충~~ json stringify 짠거 ie8버전용
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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