Skip to content

JSON

一句话解释

JSON (JavaScript 对象 Notation) 是 lightweight 文本 格式 for 存储 and exchanging 数据, based on JavaScript 对象 语法.

用大白话说

JSON 是文本-based 数据格式那个 looks 如 JavaScript 对象 literals 但使用 strict 规则: 键必须是 in 双 quotes, 否 trailing commas, 否函数, 否 undefined, and only primitive values (string, number, boolean, null) plus arrays and objects.

JavaScript provides JSON.parse() (convert a JSON string to a JavaScript value) and JSON.stringify() (convert a JavaScript value to a JSON string). These are used for saving data to localStorage, sending data to/from servers, and configuration files.

JSON is language-independent — it is used by virtually all programming languages, not just JavaScript. It is the most common format for API responses (REST APIs) and configuration files.

示例

javascript
const obj = { name: "Ada", age: 36 };
const json = JSON.stringify(obj);
console.log(json); // '{"name":"Ada","age":36}'
const parsed = JSON.parse(json);
console.log(parsed.name); // "Ada"

JSON.stringify converts 到 JSON 文本; JSON.parse converts 后面 到 JavaScript 对象.

相关术语

相关资源

相关课程

相关工具

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表