日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

json 语法_JSON的基本语法

發(fā)布時間:2023/12/1 javascript 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 json 语法_JSON的基本语法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

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是一種輕量級的可讀數(shù)據(jù)格式,其結(jié)構(gòu)類似于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,

它由兩個主要部分-鍵和值組成,它們結(jié)合在一起形成了我們看到的結(jié)構(gòu)形式。 在本文中,我們將探討一些JSON語法 ,

Key: It is a string enclosed in quotes.

關(guān)鍵字 :這是一個用引號引起來的字符串。

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

值 :它可以是字符串,數(shù)字,布爾表達式,數(shù)組,對象等,如果是字符串,也可以用引號引起來。

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.

鍵值以冒號分隔在一起時,會形成一個鍵值對,該鍵值對實際上包含其中的數(shù)據(jù)。 每個鍵值對都以逗號分隔,就像在普通JavaScript對象中一樣。 該對象括在花括號內(nèi)。

{"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數(shù)據(jù)的示例。 您可以看到上面如何遵循所有規(guī)則? 存儲鍵值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已經(jīng)借用或采用了JavaScript語法,這是非常正確的,但只是在一定程度上。 由于其語法與簡單的Javascript對象的語法高度相似,因此人們傾向于像JSON對象一樣混淆JSON。 但是,為打破泡沫,讓我指出一些區(qū)別,您可以直接訪問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中的鍵對應的值永遠不能是函數(shù)。

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中,密鑰始終被括在引號內(nèi),這與JavaScript對象不同,在JavaScript對象中,引號僅在認為必要時才包含密鑰。 我們可以說JSON所承載的語法本質(zhì)上是JavaScript對象語法的子集,并且有一些補充。

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

json 語法

總結(jié)

以上是生活随笔為你收集整理的json 语法_JSON的基本语法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。