JSON 객체를 String으로 변환하기
페이지 정보
작성자 MintState 댓글 0건 조회 21,390회 작성일 10-01-19 12:27본문
JSON 객체를 String으로 변환하기
만일 prototype.js 를 쓴다면
식으로 호출 할 수 있습니다.
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}
식으로 호출 할 수 있습니다.
|
|
댓글목록
등록된 댓글이 없습니다.





JSON 객체를 String으로 변환하기