20220501 TIL

강지훈·2022년 4월 30일
0

JSON
javascript Object Notaion

Notation:표기법

'{"name":"John","age":30,"car":null}'

이 객체는 3가지 속성을 가지는데
1.이름 2.나이 3.자동차

각각의 속성들은 값을 가진다.

Why Use JSON?
JSON 형식은 문법적으로 자바스크립트 객체를 만들때의
코드와 비슷하기때문에 자바스크립트 프로그램은
JSON 데이터를 자바객체로 쉽게 변환할수있다.

JSON의 문법적 규칙
데이터는 이름/값 쌍으로 되어있다.
데이터는 콤마로 분리된다
{}는 객체를 나타낸다
[]는 배열을 나타낸다

// Storing data:
const myObj = {name: "John", age: 31, city: "New York"};
const myJSON = JSON.stringify(myObj);
localStorage.setItem("testJSON", myJSON);

// Retrieving data:
let text = localStorage.getItem("testJSON");
let obj = JSON.parse(text);
document.getElementById("demo").innerHTML = obj.name;

profile
never stop

0개의 댓글