Tutorials 参考 练习 Menu
Paid Courses

JS教程

JS主页 JS简介 JS在哪里 JS输出 JS语句 JS语法 JS评论 JS变量 JS Let JS Const JS运算符 JS算术 JS分配 JS数据类型 JS函数 JS对象 JS活动 JS字符串 JS字符串方法 JS String Search JS String Templates JS号 JS编号方法 JS数组 JS数组方法 JS数组排序 JS数组迭代 JS Array Const JS日期 JS日期格式 JS日期获取方法 JS日期设置方法 JS数学 JS 随机 JS布尔值 JS比较 JS条件 JS开关 JS循环 JS循环 In JS循环 Of JS循环播放 JS Break JS Typeof JS类型转换 JS运算 JS正则 JS错误 JS范围 JS吊装 JS严格模式 JS此关键字 JS箭头功能 JS类 JS JSON JS调试 JS样式指南 JS最佳做法 JS错误 JS性能 JS保留字

JS版本

JS版本 JS 2009 (ES5) JS 2015 (ES6) JS 2016 JS 2017 JS 2018 JS IE / Edge JS历史记录

JS对象

对象定义 对象属性 对象方法 对象显示 对象访问器 对象构造器 对象原型 Object 参考 Object Map() Object Set()

JS函数

功能定义 功能参数 函数调用 函数调用 应用功能 功能闭包

JS类

Class Intro Class Inheritance Class Static

JS Async

JS Callbacks JS Asynchronous JS Promises JS Async/Await

JS HTML DOM

DOM简介 DOM方法 DOM文档 DOM元素 DOM HTML DOM Forms DOM CSS DOM动画 DOM事件 DOM事件监听器 DOM导航 DOM节点 DOM集合 DOM节点列表

JS浏览器BOM

JS窗口 JS屏幕 JS位置 JS历史记录 JS导航器 JS弹出警报 JS计时 JS Cookies

JS Web APIs

Web API Intro Web Forms API Web History API Web Storage API Web Worker API Web Fetch API Web Geolocation API

JS AJAX

AJAX简介 AJAX XMLHttp AJAX请求 AJAX响应 AJAX XML文件 AJAX PHP AJAX ASP AJAX数据库 AJAX应用程序 AJAX 示例

JS JSON

JSON简介 JSON语法 JSON与XML JSON数据类型 JSON解析 JSON Stringify JSON对象 JSON数组 JSON Server JSON PHP JSON HTML JSON JSONP

JS vs jQuery

jQuery选择器 jQuery HTML jQuery CSS jQuery DOM

JS 示例

JS 示例 JS HTML DOM JS HTML输入 JS HTML对象 JS HTML事件 JS浏览器 JS编辑器 JS 练习 JS测验 JS证书

JS 参考

JavaScript对象 HTML DOM对象


JSON - Introduction

HTML
JSON

JSON stands for JavaScript Object Notation

JSON is a text format for storing and transporting data

JSON is "self-describing" and easy to understand

JSON 例子

This example is a JSON string:

'{"name":"John", "age":30, "car":null}'

It defines an object with 3 properties:

  • name
  • age
  • car

Each property has a value.

If you parse the JSON string with a JavaScript program, you can access the data as an object:

let personName = obj.name;
let personAge = obj.age;

什么是JSON?

  • JSON stands for JavaScript Object Notation
  • JSON is a lightweight data-interchange format
  • JSON is plain text written in JavaScript object notation
  • JSON is used to send data between computers
  • JSON is language independent *

*
The JSON syntax is derived from JavaScript object notation, but the JSON format is text only.

Code for reading and generating JSON exists in many programming languages.

The JSON format was originally specified by Douglas Crockford.


Why Use JSON?

The JSON format is syntactically similar to the code for creating JavaScript objects. Because of this, a JavaScript program can easily convert JSON data into JavaScript objects.

Since the format is text only, JSON data can easily be sent between computers, and used by any programming language.

JavaScript has a built in function for converting JSON strings into JavaScript objects:

JSON.parse()

JavaScript also has a built in function for converting an object into a JSON string:

JSON.stringify()

You can receive pure text from a server and use it as a JavaScript object.

You can send a JavaScript object to a server in pure text format.

You can work with data as JavaScript objects, with no complicated parsing and translations.




Storing Data

When storing data, the data has to be a certain format, and regardless of where you choose to store it, text is always one of the legal formats.

JSON makes it possible to store JavaScript objects as text.