JavaScript/JavaScript
[javascript] JSON.stringify() 메소드 만들어 보기
뚱2
2012. 2. 8. 13:59
jQuery를 이용해서 만들었다.
기본적으로 jQuery를 임포트 해야 한다.
기본적으로 jQuery를 임포트 해야 한다.
var myStringify = function(data) { var msg = "" ,myData = data || {} ,mySection = "," ,isData = false ,dataType = jQuery.type(myData) ; // 배열인지 검사 if ( dataType == "array" ) { msg += "["; } else if ( dataType == "object" ) { msg += "{"; } jQuery.each(myData, function(k, v) { isData = true; var propertyType = jQuery.type(v); if ( propertyType == "array" || propertyType == "object" ) { if ( dataType == "array" ) { msg += arguments.callee(v); } else { msg += "\"" + k + "\":" + arguments.callee(v); } msg += mySection; } else { if ( dataType == "array" ) { msg += v; } else { msg += "\"" + k + "\":"; if ( propertyType == "string" ) { msg += "\"" + v + "\""; } else { msg += "" + v; } } msg += mySection; } });//jQuery.each(myData, function(k, v) { if ( isData == true ) { msg = msg.substring(0, msg.length-1); } if ( dataType == "array" ) { msg += "]"; } else if ( dataType == "object" ) { msg += "}"; } return msg; };//var myStringify = function(data) {