瓜瓜笔记 | 让你彻彻底底搞懂 JSON
是的,正如你所想,json大家都知道,非常简单,但是有一些小坑和概念要是没弄清楚,总有一天会出bug的。于是就有了今天这篇小短文.....
1{
2 “firstName” : “John” ,
3 “lastName” : “Smith” ,
4 “isAlive” :true ,
5 “age” : 27 ,
6 “address” : {
7 “streetAddress” : “212nd Street” ,
8 “city” : “New York“ ,
9 ”state“ : ”NY“ ,
10 ”postalCode“ : ”10021-3100“
11 },
12 ”phoneNumbers“ : [
13 {
14 ”type“ : “home” ,
15 “number” : “212555-1234”
16 },
17 {
18 “type” : “office” ,
19 “number” : “646555-4567”
20 },
21 {
22 “type” : “mobile” ,
23 “number” : “123456-7890”
24 }
25 ],
26 “children” : [],
27 “配偶“ :null
28}
什么是JSON
- 指的是 JavaScript 对象表示法(JavaScript Object Notation)
- 是轻量级的文本数据交换格式
- 独立于语言: 使用 Javascript语法来描述数据对象,但仍然独立于语言和平台。
- JSON 解析器和 JSON 库支持许多不同的编程语言。
- JSON 具有自我描述性,更易理解
JSON语法
JSON语法是JavaScript语法的子集。
JSON语法规则
JSON语法是JavaScript对象表示语法的子集。是一个标记符的序列。这套标记符包含六个构造字符、字符串、数字和三个字面名。JSON是一个序列化的对象或数组。
- 数据在名称/值对中
- 数据由逗号分隔
- 大括号保存对象
- 中括号保存数组
- JSON名称/值对
"name" : "瓜瓜笔记"
这很容易理解,等价于这条 JavaScript 语句:name = "瓜瓜笔记"
- 数字(整数或浮点数)
- 字符串(在双引号中)
- 逻辑值(true 或 false)
- 数组(在中括号中)
- 对象(在大括号中)
- null
{ "flag":true }
{ "name":"瓜瓜笔记" , "url":"www.xxxx.com" }
这一点也容易理解,与这条 JavaScript 语句等价:name =
"瓜瓜笔记"2url =
"www.xxxx.com"{ "age":30 }
JSON null
JSON可以设置null值:
{ "runoob":null }
{
2"sites": [
3{
"name":
"瓜瓜笔记" ,
"url":
"www.xxxx.com" },
4{
"name":
"google" ,
"url":
"www.google.com" },
5{
"name":
"微博" ,
"url":
"www.weibo.com" }
6]
7}
推荐阅读
喜欢就点击“在看”吧!
最新评论
推荐文章
作者最新文章
你可能感兴趣的文章
Copyright Disclaimer: The copyright of contents (including texts, images, videos and audios) posted above belong to the User who shared or the third-party website which the User shared from. If you found your copyright have been infringed, please send a DMCA takedown notice to [email protected]. For more detail of the source, please click on the button "Read Original Post" below. For other communications, please send to [email protected].
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。