Reference JavaScript reference

JSON.stringify 参考

JSON.stringify Reference,整理语法、参数、示例、返回值和常见错误,适合快速查询 JavaScript 写法。

语法

js
const result = JSON.stringify(value);

参数

  • value:要序列化的 JavaScript 值。
  • replacer / space:可选,控制字段过滤和缩进。

返回值

返回 JSON 字符串。

示例

js
const text = JSON.stringify({ name: "caijiao" }, null, 2);
console.log(text);

常见错误

  • 把普通对象字符串当 JSON 解析会失败,JSON 字符串必须使用双引号。

相关内容