Javascript JSON.parse(), JSON.stringify() 사용하는법

Leedu 2016.07.04 14:25

안녕하세요.

 

오늘은 자바스크립트의 메소드인 JSON.parse()와 JSON.stringify()에 대해 알아보겠습니다.

 

JSON.parse()란?

  • parse 메소드는 string 개체를 json 객체로 변환시켜줍니다.

 

 

JSON.stringify란?

  • stringify 메소드는 json 객체를 String 객체로 변환시켜 줍니다.

 

 

Example 1)

    var data = {

        Name: "SooYoung"

        , Age: "27"

    }

 

    var person = JSON.stringify(data);

    var oPerson = JSON.parse(person);

 

    //output

    alert(person);

    /* Output: "{"Name":"SooYoung","Age":"29"}" */

    alert(oPerson);

    /* Output: Object */

 

Example 2)

<front-ent>

    function signup()

    {

        var member = {

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

            "email": "test@naver.com",

            "password": "1234"

        };

        

        $.ajax({

            url : '/account/signup',

            dataType : 'json',

            type : 'POST',

            data : JSON.stringify(member), //그냥 member 사용하면 error 발생!

            contentType : 'application/json; charset=UTF-8',

            success : function(result) {

//TODO

                console.log(result);

            }

        });

    }

 

<back-end>

    @RequestMapping(value = "/signup", method = RequestMethod.POST)

    public MemberResultDto signup(@RequestBody Member member)  

    {                         

        systemLog.info("try to sign up..");

//TODO 

        return memberResultDto;

    }
 

@RequestBody는 HTTP요청의 body 내용을 자바 객체로 매핑 하는 역할을 합니다.

 

 

모두 즐거운 코딩 하세요~



출처: http://ithub.tistory.com/54 [Fall in IT.]

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
123 Mouse-Picking Collada Models with THREE.js 졸리운_곰 2017.05.30 394
122 3D development with WebGL, Part 3 file 졸리운_곰 2017.05.30 492
121 3D development with WebGL, Part 2 file 졸리운_곰 2017.05.30 549
120 3D development with WebGL, Part 1 file 졸리운_곰 2017.05.30 562
119 THREE.JS EXPERIMENT 2 – SELECTION/HIGHLIGHTING file 졸리운_곰 2017.05.30 513
118 Selections in THREE.js I file 졸리운_곰 2017.05.30 288
117 learning-threejs/chapter-02/05-custom-geometry.html 졸리운_곰 2017.05.30 450
116 Vector3 : three.js 졸리운_곰 2017.05.30 394
115 Three.js를 사용한 기본 3D 그래픽 file 졸리운_곰 2017.05.30 743
114 Three.js projecting mouse clicks to a 3D scene - how to do it and how it works file 졸리운_곰 2017.05.30 469
113 자바스크립트와 Node.js를 이용한 웹 크롤링 테크닉 file 졸리운_곰 2017.05.27 570
112 Three.js Geometry three.js 기하도형 file 졸리운_곰 2017.05.27 516
111 Web3D Technologies , 현존 web3d 기술 총람 졸리운_곰 2017.05.27 248
110 JSON - 자바스크립트 강좌 JS / CSE file 졸리운_곰 2017.05.06 499
» Javascript JSON.parse(), JSON.stringify() 사용하는법 졸리운_곰 2017.05.06 492
108 JSON Text를 JSON Object로 변환하기 졸리운_곰 2017.05.06 476
107 WebGL / Three.js - 시작하기 ( Getting Started ) #03 본문 file 졸리운_곰 2017.05.05 512
106 WebGL / Three.js - 시작하기 ( Getting Started ) #02 본문 file 졸리운_곰 2017.05.05 320
105 WebGL / Three.js - 시작하기 ( Getting Started ) #01 본문 file 졸리운_곰 2017.05.05 363
104 WebGL 3D 프로그래밍 [HTML5와 자바스크립트, 웹지엘로 만드는 웹 3D 그래픽] file 졸리운_곰 2017.05.03 500
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED