반응형

javascript 객체를 JSON 객체로 변환하는 함수.

JSON.parse() : JSON 형태 문자열을 자바스크립트 객체로 변환

JSON.stringify() : 자바스크립트 객체를 JSON 형슥으로 변환

  1. <script type="text/javascript">
  2.     var obj = {
  3.         name : "TEST",
  4.         gender : "Male"
  5.     };
  6.     console.log(obj);
  7.     console.log(JSON.stringify(obj));
  8.  
  9.     var date = new Date();
  10.  
  11.     console.log(date);
  12.     console.log(date.toJSON());
  13.     console.log(JSON.stringify(date));
  14.     console.log(JSON.stringify(date.toJSON()));
  15. </script>

결과값

Object {name: "TEST", gender: "Male"} test.html:10
{"name":"TEST","gender":"Male"} test.html:11
Fri May 10 2013 08:59:51 GMT+0900 (대한민국 표준시) test.html:15
2013-05-09T23:59:51.036Z test.html:16
"2013-05-09T23:59:51.036Z" test.html:17
"2013-05-09T23:59:51.036Z"

정말 요즘 javascript, jquery때문에 헷갈려 죽겠다. ㅠㅠ

728x90
반응형

'Development > Frontend skills' 카테고리의 다른 글

React 에서 props 사용  (0) 2017.01.09
React.. 끄적끄적.  (0) 2017.01.09
Mac 에서 Node.js 설치  (0) 2017.01.05
jquery radio button 속성 설정  (0) 2013.09.04
JavaScript var Scope  (0) 2013.03.15

+ Recent posts