javascript _JSON

장봄·2020년 5월 25일
1

code-states_4주차

목록 보기
1/13
post-thumbnail

[JSON]

속성-값 쌍 또는 "키-값 쌍"으로 이루어진 데이터 오브젝트를 전달하기 위해 인간이 읽을 수 있는 텍스트를 사용하는 개방형 표준 포맷

  • JSON객체는 Global 객체이다.

지원하는 데이터 형식

  • Number

  • String

  • Boolean

  • Array

  • Object

  • null

JSON객체

  • JSON.parse() : JSON 문자열의 구문을 분석하고, Number, String, Boolean, Array, Object, null 을 생성
console.log( JSON.parse('1') );
// 1
console.log( JSON.parse('"abc"') );
// abc
console.log( JSON.parse('true') );
// true
console.log( JSON.parse('[1,2,3]') );
// [1, 2, 3]
console.log( JSON.parse('{"a":"b"}') );
// {a: "b"}
console.log( JSON.parse('null') );
// null
  • JSON.stringify() : 값이나 객체를 JSON 문자열로 변환

출처 : https://medium.com/@pks2974/javascript-%EC%99%80-json-f098a8f6ae77


[localStorage]

브라우저 창이 닫힌 후에도 만료 날짜가없는 데이터

메소드

  • localStorage.setItem('key', 'value') : 데이터 추가

  • localStorage.getItem('key') : 특정 키를 얻는 방법

  • localStorage.removeItem('key') : 데이터 제거

  • localStorage.clear() : 모든 저장소가 제거

좋은 사이트

profile
즐겁게 배우고 꾸준히 블로깅하는 개발자입니다 ;>

0개의 댓글