강의노트 - 12

김희목·2024년 7월 19일
0

패스트캠퍼스

목록 보기
20/53

표준내장객체

JSON

JSON(JavaScript Object Notation)

  1. 데이터 전달을 위한 표준 포맷!
  2. 문자, 숫자, 불린, Null, 객체, 배열만 사용
  3. 문자는 큰 따옴표만 사용
  4. 후행 쉼표 사용 불가
  5. .json 확장자 사용

JSON.stringify()

= 데이터를 JSON 문자로 변환합니다.

JSON.parse()

= JSON 문자를 분석해 데이터로 변환합니다.

cosole.log(JSON.stringify('Hello world!'))
cosole.log(JSON.stringify(123))
cosole.log(JSON.stringify(false))
cosole.log(JSON.stringify(null))
cosole.log(JSON.stringify({ name: 'Heropy', age: 85 }))
cosole.log(JSON.stringify([1,2,3]))

console.log(JSON.parse('"Hello world!"'))
console.log(JSON.parse('123'))
console.log(JSON.parse('false'))
console.log(JSON.parse('null'))
console.log(JSON.parse('{"name":"Heropy", "age":85}'))
console.log(JSON.parse('[1,2,3]'))

0개의 댓글