json 语法_JSON的基本语法

json 语法

JSON which stands for JavaScript Object Notation is a lightweight readable data format that is structurally similar to a JavaScript object much like its name suggests.

代表JavaScript Object Notation的 JSON是一种轻量级的可读数据格式,其结构类似于JavaScript对象,就象其名称所暗示的那样。

It consists of two primary parts- keys and values which together combine to give it the form of the structure that we see. In this article, we'll explore some JSON syntax,

它由两个主要部分-键和值组成,它们结合在一起形成了我们看到的结构形式。 在本文中,我们将探讨一些JSON语法

Key: It is a string enclosed in quotes.

关键字 :这是一个用引号引起来的字符串。

Value: It can be a string, number, boolean expression, array, object, etc and is also enclosed in quotes if it's a string.

:它可以是字符串,数字,布尔表达式,数组,对象等,如果是字符串,也可以用引号引起来。

The key-value, when come in together separated by a colon, forms a key-value pair that essentially contains the data inside it. Every key-value pair is separated by a comma, much like in a normal JavaScript Object. The object is enclosed within curly braces.

键值以冒号分隔在一起时,会形成一个键值对,该键值对实际上包含其中的数据。 每个键值对都以逗号分隔,就像在普通JavaScript对象中一样。 该对象括在花括号内。

{
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
}

Above is an example of some JSON data. You can see how all the rules are being followed above? The file extension for a file storing key-value JSON pairs is '.json' and it has a mime type of 'application/json'.

上面是一些JSON数据的示例。 您可以看到上面如何遵循所有规则? 存储键值JSON对的文件的文件扩展名是'.json' ,并且具有mime类型'application / json'

You may say that JSON has borrowed or taken JavaScript syntax and it is very true but only to a certain extent. Since it's syntax is highly similar to that of a simple Javascript object people tend to confuse JSON as exactly like a JavaScript object. However, to break your bubble let me point out some differences, you can access a JavaScript object directly but not a JSON.

您可能会说JSON已经借用或采用了JavaScript语法,这是非常正确的,但只是在一定程度上。 由于其语法与简单的Javascript对象的语法高度相似,因此人们倾向于像JSON对象一样混淆JSON。 但是,为打破泡沫,让我指出一些区别,您可以直接访问JavaScript对象,但不能访问JSON。

var obj={
name: 'John',
type:'wwe'
}
Obj;
Obj["name"];

Output

输出量

{name: "John", type: "wwe"}
"John"

We can't do something that we did above with JSON. Also under the key-value pairs, a typical JavaScript object can have methods as properties or the value whereas the value corresponding to a key in JSON can never be a function.

我们无法使用JSON做上面的事情。 同样在键值对下,典型JavaScript对象可以将方法用作属性或值,而与JSON中的键对应的值永远不能是函数。

var pokemon={
name: 'Squirtle',
type: 'Water',
HP:   100,
speak: function(){
console.log(this.name+' says hi!');
}
}
undefined
pokemon.speak();

Output

输出量

Squirtle says hi!

Also, some syntax difference is there like in a JSON the key is always enclosed inside quotes unlike in a JavaScript object where the quotes enclose a key only if deemed necessary. We can say the syntax that JSON carries is essentially a subset of the syntax of a JavaScript Object, with some additions to it.

而且,在语法上存在一些差异,例如在JSON中,密钥始终被括在引号内,这与JavaScript对象不同,在JavaScript对象中,引号仅在认为必要时才包含密钥。 我们可以说JSON所承载的语法本质上是JavaScript对象语法的子集,并且有一些补充。

翻译自: https://www.includehelp.com/json/basic-syntax-of-json.aspx

json 语法

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/377116.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

RFC3261(17 事务)

SIP是一个基于事务处理的协议:部件之间的交互是通过一系列相互独立的消息交换来完成的。特别是,一个SIP 事务由一个单个请求和这个请求的所有应答组成,这些应答包括了零个或者多个临时应答以及一个或者多个终结应答。在事务中,当请…

HDUOJ---1754 I Hate It (线段树之单点更新查区间最大值)

I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 33469 Accepted Submission(s): 13168 Problem Description很多学校流行一种比较的习惯。老师们很喜欢询问,从某某到某某当中,…

WEG的完整形式是什么?

WEG:邪恶邪恶的咧嘴 (WEG: Wicked Evil Grin) WEG is an abbreviation of "Wicked Evil Grin". WEG是“ Wicked Evil Grin”的缩写 。 It is also known as EWG (Evil Wicked Grin) "Grin" refers to a broad smile. "Wicked" refer…

C# 把数字转换成链表

例如&#xff1a;123456转换成 1 -> 2 -> 3-> 4-> 5-> 6 View Code static LinkedList<int> CovertIntToLinkedList(int num){Stack<int> stack new Stack<int>();LinkedList<int> result new LinkedList<int>();while (num!0…

《MySQL 8.0.22执行器源码分析(4.1)Item_sum类以及聚合》

Item_sum类用于SQL聚合函数的特殊表达式基类。 这些表达式是在聚合函数&#xff08;sum、max&#xff09;等帮助下形成的。item_sum类也是window函数的基类。 聚合函数&#xff08;Aggregate Function&#xff09;实现的大部分代码在item_sum.h和item_sum.cc 聚合函数限制 不…

Java 性能优化实战记录(2)---句柄泄漏和监控

前言: Java不存在内存泄漏, 但存在过期引用以及资源泄漏. (个人看法, 请大牛指正) 这边对文件句柄泄漏的场景进行下模拟, 并对此做下简单的分析.如下代码为模拟一个服务进程, 忽略了句柄关闭, 造成不能继续正常服务的小场景. 1 public class FileHandleLeakExample {2 3 p…

什么是Java文件?

Java文件 (Java files) The file is a class of java.io package. 该文件是java.io包的类。 If we create a file then we need to remember one thing before creating a file. First, we need to check whether a file exists of the same name or not. If a file of the sa…

绕过本地验证提交HTML数据

我们在入侵一个网站,比如上传或者自己定义提交的文件时,会在本地的代码中遇到阻碍,,也就是过 滤,过滤有两种,一种是在远程服务器的脚本上进行的过滤,这段代码是在服务器上运行后产生作用的,这种过 滤方式叫做远程过滤;另一种是在我们的IE浏览器里执行的脚本过滤,就是说是在我们…

《dp补卡——343. 整数拆分、96. 不同的二叉搜索树》

343. 整数拆分 1、确定dp数组以及下标含义。 dp[i]&#xff1a;分拆数字i&#xff0c;可以得到的最大的乘积 2、确定递推公式&#xff1a; dp[i]最大乘积出处&#xff1a;从1遍历j到i&#xff0c;j * dp[i-j] 与 j * (i-j)取最大值。( 拆分j的情况&#xff0c;在遍历j的过程…

Adroid学习之 从源码角度分析-禁止使用回退按钮方案

有时候&#xff0c;不能让用户进行回退操作&#xff0c;如何处理&#xff1f; 查看返回键触发了哪些方法。在打开程序后把这个方法禁止了。问题&#xff1a;程序在后台驻留&#xff0c;这样就会出现&#xff0c;其他时候也不能使用回退按钮。如何处理&#xff0c;在onpase()时方…

骑士游历问题问题_骑士步行问题

骑士游历问题问题Problem Statement: 问题陈述&#xff1a; There is a chessboard of size NM and starting position (sx, sy) and destination position (dx,dy). You have to find out how many minimum numbers of moves a knight goes to that destination position? 有…

Android基础之用Eclipse搭建Android开发环境和创建第一个Android项目(Windows平台)...

一、搭建Android开发环境 准备工作&#xff1a;下载Eclipse、JDK、Android SDK、ADT插件 下载地址&#xff1a;Eclipse:http://www.eclipse.org/downloads/ JDK&#xff1a;http://www.oracle.com/technetwork/java/javase/downloads/jdk7u9-downloads-1859576.html Android SD…

《dp补卡——01背包问题》

目录01背包[416. 分割等和子集](https://leetcode-cn.com/problems/partition-equal-subset-sum/)[1049. 最后一块石头的重量 II](https://leetcode-cn.com/problems/last-stone-weight-ii/)[494. 目标和](https://leetcode-cn.com/problems/target-sum/)01背包 1、dp数组以及…

用JavaScript往DIV动态添加内容

参考&#xff1a;http://zhidao.baidu.com/link?url6jSchyqPiEYCBoKdOmv52YHz9r7MTBms2pK1N6ptOX1kaR2eg320mlW1Sr6n36hpOeOadBxC2rWWGuhZPbms-K <div id"show"></div>要填充的数据为: 这是一个测试例子.jquery&#xff1a;$(function(){ var data …

《dp补卡——完全背包问题》

N件物品和一个最多能背重量为W的背包。第i件物品的重量为weight[i]&#xff0c;得到的价值是value[i]。每件物品都有无限个(可以放入背包多次)&#xff0c;求解将哪些物品装入背包里物品价值总和最大。 01背包和完全背包唯一不同在于遍历顺序上。 01背包的核心代码&#xff1a…

Java中的类型转换

类型转换 (Typecasting) Typecasting is a term which is introduced in all the language similar to java. Typecasting是一个用与Java类似的所有语言引入的术语。 When we assign primitive datatype to another datatype. 当我们将原始数据类型分配给另一个数据类型时。 I…

让crash文件中的内存地址变成函数名称,

假如程序员编译了inhouse给测试。 如果在测试过程中出现奔溃现象&#xff0c;我想程序员一般会来看Device Log 也就是 crash文件 如果crash文件遇到如下的情况&#xff0c;在重要的地方看不到函数名称。我想是一件很奔溃的事情。 1 Exception Type: EXC_BAD_ACCESS (SIGSEGV)2…

《dp补卡——多重背包》

多重背包简介&#xff1a; 有N种物品和一个容量为V的背包。第i种物品最多有Mi件可用&#xff0c;每件耗费的空间为Ci&#xff0c;价值为Wi。求解将哪些物品装入背包可使得这些物品耗费的空间总和不超过背包容量&#xff0c;且价值总和最大。 将Mi件摊开&#xff0c;就是一个01背…

kafka消息确认ack_什么是确认(ACK)? ACK代表什么?

kafka消息确认ackACK&#xff1a;致谢 (ACK: Acknowledgment) An acknowledgment (ACK) is a signal that is passed among the communicating processes, computers, or devices to indicate acknowledgment, or delivery of the message, as a component of a communications…

CocoaAsyncSocket 套接字

CocoaAsyncSocket 套接字 https://github.com/robbiehanson/CocoaAsyncSocket Asynchronous socket networking library for Mac and iOS 用于iOS以及Mac的异步套接字网络库。 TCP GCDAsyncSocket and AsyncSocket are TCP/IP socket networking libraries. Here are the key…