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

안녕하세요.

 

오늘은 자바스크립트의 메소드인 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-end>

    function signup()

    {

     var member = {

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

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.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 내용을 자바 객체로 매핑 하는 역할을 합니다.

 

 

모두 즐거운 코딩 하세요~

[출처] https://ithub.tistory.com/54

 

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
27 [wordpress, 워드프레스] 워드프레스로 쉽게 랜딩 페이지 만들기 (feat. 엘리멘터, GeneratePress, Divi) file 졸리운_곰 2024.12.20 545
26 [wordpress, 워드프레스] WordPress 페이지또는 글에 별도 CSS와 JavaScript 추가하기 file 졸리운_곰 2024.12.19 354
25 [wordpress 플러그인] 코스모스팜. 회원관리 1.메뉴에 로그인 넣기 file 졸리운_곰 2024.08.25 513
24 [wordpress 플러그인] WP-Members로 회원제 사이트 만들기 file 졸리운_곰 2024.08.25 749
23 [php worldpress] 워드프레스 새 서버 이전시 페이지 안나오는 문제 : How to Rewrite URLs with mod_rewrite for Apache on Ubuntu 20.04 file 졸리운_곰 2024.08.07 774
22 [php worldpress] PHP query to SQL server database (wordpress) 졸리운_곰 2024.07.28 503
21 [php worldpress] [위 에]wordpress 사용자 암호 화 원리 및 알고리즘 분석 졸리운_곰 2022.04.11 377
20 [wordpress] WPForms 워드프레스 폼빌더 사용법 file 졸리운_곰 2021.04.25 1715
19 [wordpress][워드프레스] 워드프레스에서 wpdb를 사용한 CRUD 작업 예 졸리운_곰 2021.04.15 356
18 워드프레스에서 wpdb를 사용한 CRUD 작업 예 졸리운_곰 2021.01.12 459
17 워드프레스 – CRUD file 졸리운_곰 2021.01.02 501
16 워드프레스 데이터베이스 들여다보기. file 졸리운_곰 2020.08.04 673
15 워드프레스 플러그인과 테마 비교 - 사이트별 플러그인 만들기 졸리운_곰 2020.04.21 501
14 워드프레스에서 js 스크립트 파일과 스타일시트를 올바르게 로드하는 방법 졸리운_곰 2020.04.21 735
13 워드프레스 플러그인 만들기 file 졸리운_곰 2020.04.21 499
12 워드프레스 숏코드: 완벽 가이드 file 졸리운_곰 2020.04.21 513
11 워드프레스 페이지 분석 file 졸리운_곰 2019.11.19 515
10 내가 본 워드프레스 핵심 구조 및 기능 (Wordpress Architecture and Function) file 졸리운_곰 2019.11.19 452
9 Embedding three.js in WordPress 워드프레스에서 three.js 사용 졸리운_곰 2019.11.08 517
8 How to Super Charge your WordPress with Microservices 워드프레스 마이크로서비스 file 졸리운_곰 2019.11.03 373
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED