JSON 字符串中的属性名必须加双引号
JSON 分类:JSON 对象{},JSON 数组[]
JSON 中允许的值:字符串,数值,布尔值,null,普通对象,数组
IE 7+json2.js插件

JSON 字符串转对象

  1. const jsO = '{ "name": "yingximu", "age": 18 }';
  2. const jsA = "[1, 2, 3]";
  3. console.log(JSON.parse(jsO)); // {name: "yingximu", age: 18}
  4. console.log(JSON.parse(jsA)); // [1, 2, 3]

对象转 JSON 字符串

  1. const obj = { name: "yingximu", age: 18 };
  2. const arr = [1, 2, 3];
  3. console.log(JSON.stringify(obj)); // {"name":"yingximu","age":18}
  4. console.log(JSON.stringify(arr)); // [1,2,3]