자바 스크립트 구문 분석 json
var jsonPerson = '{"first_name":"billy", "age":23}';
var personObject = JSON.parse(jsonPerson); //parse json string into JS object
json javascript 에 대한 객체
var person={"first_name":"Tony","last_name":"Hawk","age":31};
var personJSONString=JSON.stringify(person);
js 를 json 으로 변경
var obj = {name: "Martin", age: 30, country: "United States"};
// Converting JS object to JSON string
var json = JSON.stringify(obj);
console.log(json);
// Prints: {"name":"Martin","age":30,"country":"United States"}
"https://www.tutorialrepublic.com/faq/how-to-convert-js-object-to-json-string.php"
변환 json.자바 스크립트에서 배열에 stringify
const myObj = {
name: 'Skip',
age: 2,
favoriteFood: 'Steak'
};
const myObjStr = JSON.stringify(myObj);
console.log(myObjStr);
// "{"name":"Skip","age":2,"favoriteFood":"Steak"}"
console.log(JSON.parse(myObjStr));
// Object {name:"Skip",age:2,favoriteFood:"Steak"}
javascript 객체를 문자열 화
console.log(JSON.stringify({ x: 5, y: 6 }));
// expected output: "{"x":5,"y":6}"
console.log(JSON.stringify([new Number(3), new String('false'), new Boolean(false)]));
// expected output: "[3,"false",false]"
console.log(JSON.stringify({ x: [10, undefined, function(){}, Symbol('')] }));
// expected output: "{"x":[10,null,null,null]}"
console.log(JSON.stringify(new Date(2006, 0, 2, 15, 4, 5)));
// expected output: ""2006-01-02T15:04:05.000Z""
javascript 에서 일반 객체를 json 객체로 변환하는 방법
var obj = { name: "John", age: 30, city: "New York" };
var myJSON =
JSON.stringify(obj);
document.getElementById("demo").innerHTML = myJSON;