标签:规范 跳过 def 通用 rev serialize ret define 编程语言
1 let student = { 2 name: ‘John‘, 3 age: 30, 4 isAdmin: false, 5 courses: [‘html‘, ‘css‘, ‘js‘], 6 wife: null 7 }; 8 9 let json = JSON.stringify(student); 10 console.log(json) // {"name":"John","age":30,"isAdmin":false,"courses":["html","css","js"],"wife":null}
1 let user = { 2 sayHi() { // 被忽略 3 alert("Hello"); 4 }, 5 [Symbol("id")]: 123, // 被忽略 6 something: undefined // 被忽略 7 }; 8 9 console.log(JSON.stringify(user)); // {}(空对象) // {}
如果我们需要解析JSON字符串,需要另一个方法 JSON.parse(str, [reviver])。
1 let str = ‘{"title":"Conference","date":"2017-11-30T12:00:00.000Z"}‘; 2 3 let meetup = JSON.parse(str, function (key, value) { 4 if (key == ‘date‘) return new Date(value); 5 return value; 6 }); 7 8 console.log(meetup.date.getDate()); // 30
标签:规范 跳过 def 通用 rev serialize ret define 编程语言
原文地址:https://www.cnblogs.com/feng-fengfeng/p/12419535.html