JSON이란?
- Javascript Object Notation의 약자
- 서버와 데이터를 주고받을 때 사용하는 Data 형태
- Data를 표시하는 포맷일 뿐, 프로그래밍 문법은 아니다
- 객체의 내용을 기술하기 위한 단순 text
Javascript Object란?
- Object는 JS Engine 메모리 안에 있는 데이터 구조
- 자바스크립트 문법에서 사용되는 데이터 유형
- key-value로 이루어진 데이터 형식
let jsonExample = '{"album" : [{"order" : "1" , "title" : "INVU"}, {"order" : "2", "title" : "some nigths"}]}'
let objectExample = {song : [{order : 1 , title : "INVU"}, {order : 2, title : "some nigths"}]}
JSON.parse()
- JSON을 Object 형식으로 변환
let example = '{"song" : [{"order" : "1" , "title" : "INVU"}, {"order" : "2", "title" : "some nigths"}]}' console.log(JSON.parse(example)); // { song: [ { order: '1', title: 'INVU' }, { order: '2', title: 'some nigths' } ] }
JSON.stringify()
- Object를 JSON 형식으로 변환
let example = {song : [{order : 1 , title : "INVU"}, {order : 2, title : "some nigths"}]}; console.log(JSON.stringify(example)); // {"song":[{"order":1,"title":"INVU"},{"order":2,"title":"some nigths"}]}