博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
json 语法_JSON的基本语法
阅读量:2533 次
发布时间:2019-05-11

本文共 2991 字,大约阅读时间需要 9 分钟。

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 . 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' ,并且具有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!'); }}undefinedpokemon.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对象语法的子集,并且有一些补充。

翻译自:

json 语法

转载地址:http://bfxzd.baihongyu.com/

你可能感兴趣的文章
学习操作系统导图
查看>>
在线的JSON formate工具
查看>>
winform非常实用的程序退出方法!!!!!(转自博客园)
查看>>
xml解析
查看>>
centos安装vim
查看>>
linux工作调度(计划任务)
查看>>
hdu--1698 Just a Hook(线段树+区间更新+懒惰标记)
查看>>
Python学习笔记-EXCEL操作
查看>>
二月二——头牙诗词
查看>>
《吴忠与富平》之四:汉三水属国(北地属国、安定属国)
查看>>
丁酉立秋喜逢风雨
查看>>
vim删除#开头的行和正则表达式笔记
查看>>
python3 提成计算
查看>>
VBA赋值给指定单元格
查看>>
抽象类和接口总结回顾
查看>>
【语言处理与Python】5.3使用Python字典映射词及其属性
查看>>
设备信息
查看>>
Android Volley框架的使用(三)
查看>>
[错误总结] 控件frame设置无效
查看>>
Redis Java API
查看>>