[Node.js] JSON에 대해

jungeundelilahLEE·2021년 2월 9일
0

Node.js

목록 보기
27/27

goal


  • json() 과 JSON.parse, JSON.stringify 헷갈리는 표현 알아보기

json()

  • json() 은 fetch 전용 기능이다.
  • 응답을 받을 때, json형태로 받고 싶을 때 사용 (.html, .text 등도 사용가능)

JSON.parse (json을 obj로 만든다)

JSON.stringify (obj를 json으로 만든다)

let obj = {user : "delilah", city : "seoul"}

let makeJson = JSON.stringify(obj) 
console.log(makeJson) // "{"user":"delilah","city":"seoul"}
"

let makeObj = JSON.parse(makeJson)
console.log(makeObj) // {user: "delilah", city: "seoul"}
  • 객체를 강제로 문자열로 변환하려고 하며 예를들면 [object object] 이러한 형태로 나온다.
profile
delilah's journey

0개의 댓글