니가 알고 있는 JSON에 관한 모든 것들parse()와 JSON.stringify()

1851 단어 javascriptjson

JSON.stringify()

Transforms a Javascript object to a JSON string.
A common use of JSON is to exchange data to/from a web server.
When sending data to a web server, the data has to be a string.
Convert a JavaScript object into a string with JSON.stringify().


예:
JavaScript에 다음과 같은 객체가 있다고 가정합니다.
const student = {
    name: "Alex",
    age: 20,
    email: "[email protected]"
};

const studentStr = JSON.stringify(student);
console.log(studentStr);

{ "name":"Alex", "age":20, "email":"[email protected]"}

문자열화된 JavaScript 배열

It is also possible to stringify JavaScript arrays.


예:
JavaScript에 다음과 같은 객체가 있다고 가정합니다.
const arrName = [ "John", "Peter", "Sally", "Jane" ];

const jsonName = JSON.stringify(arrName);
console.log(jsonName);

["John","Peter","Sally","Jane"]

JSON.해결()

Takes a JSON string and transform it into a Javascript Object.


예:
우리가 웹 서버에서 이 텍스트를 받았다고 상상해 보세요.
우리는 상술한 studentStr 샘플을 채택할 것이다.
const jsObject = JSON.stringify(studentStr);
console.log(jsObject);

Object { age: 20, email: "[email protected]", name: "Alex" }

좋은 웹페이지 즐겨찾기