Skip to content

JSON 객체를 String으로 변환하기

MintState January 19, 2010 at 12:27 PM Views 21970

JSON 객체를 String으로 변환하기

function JSONtoString(object) {
 	var results = [];
 	for (var property in object) {
		var value = object[property];
		if (value)
			results.push(property.toString() + ': ' + value);
	}
	return '{' + results.join(', ') + '}';
}
var obj = { "id":"outsider", "sex":"male" };
obj = JSONtoString(obj);
alert(obj); // {id: outsider, sex: male}
alert(typeof obj); // string

만일 prototype.js 를 쓴다면

alert(Object.toJSON(obj)); // {id: outsider, sex: male}

식으로 호출 할 수 있습니다.

Share X Facebook LINE QR code

0 comments

Be the first to comment.