當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
JSON语法介绍
? 官網(wǎng):https://www.json.org/ ? ? JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language. 譯: JSON(JavaScript Object Notation)是一種輕量級的數(shù)據(jù)交換格式。 人類很容易讀寫。 機器很容易解析和生成。 它基于JavaScript編程語言的一個子集,標準ECMA-262第3版 - 1999年12月.JSON是一種完全獨立于語言的文本格式,但使用C語言系列程序員熟悉的約定,包括C語言 ,C ++,C#,Java,JavaScript,Perl,Python等等。 這些屬性使JSON成為理想的數(shù)據(jù)交換語言。 ? JSON is built on two structures: * A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array. * An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence. 譯: JSON基于兩種結(jié)構(gòu): 名稱/值對的集合。 在各種語言中,這被實現(xiàn)為對象,記錄,結(jié)構(gòu),字典,散列表,鍵控列表或關(guān)聯(lián)數(shù)組。 有序的值列表。 在大多數(shù)語言中,這被實現(xiàn)為數(shù)組,向量,列表或序列。 ? These are universal data structures. Virtually all modern programming languages support them in one form or another. It makes sense that a data format that is interchangeable with programming languages also be based on these structures. 譯: 這些是通用數(shù)據(jù)結(jié)構(gòu)。 實際上,所有現(xiàn)代編程語言都以某種形式支持它們。 有意義的是,可與編程語言互換的數(shù)據(jù)格式也基于這些結(jié)構(gòu)。 ? ? In JSON, they take on these forms: ? 1. An object is an unordered set of name/value pairs. An object begins with { (left brace) and ends with } (right brace). Each name is followed by : (colon) and the name/value pairs are separated by , (comma). 譯: 在JSON中,他們采用以下形式: ? 對象是一組無序的名稱/值對。 對象以{(左括號)開頭,以}結(jié)尾(右括號)。 每個名稱后跟:(冒號),名稱/值對用(逗號)分隔。 ? ? 總結(jié):用花括號表示對象,名稱/值對可以有多個,并用逗號分隔 ? 示例: { "firstName":"John" , "lastName":"Doe" } 一個{}就是一個JSONObject ? 2. An array is an ordered collection of values. An array begins with [ (left bracket) and ends with ] (right bracket). Values are separated by , (comma). 譯: 數(shù)組是有序的值集合。 數(shù)組以[(左括號)開頭并以]結(jié)尾(右括號)。 值以(逗號)分隔。 ? 總結(jié):用方括號表示數(shù)組,值以逗號分隔 ? 示例: 數(shù)組可包含多個對象 { "employees": [ { "firstName":"John" , "lastName":"Doe" }, { "firstName":"Anna" , "lastName":"Smith" }, { "firstName":"Peter" , "lastName":"Jones" } ] } ? 說明:employees的值是一個數(shù)組,數(shù)組的元素是3個對象,每個對象是名稱/值對,3個對象之間以逗號分隔 ? 3. A value can be a string in double quotes, or a number, or true or false or null, or an object or an array. These structures can be nested. 譯: 值可以是雙引號中的字符串,數(shù)字,或true或false或null,或?qū)ο蠡驍?shù)組。 這些結(jié)構(gòu)可以嵌套。 ? JSON 值可以是:
- 數(shù)字(整數(shù)或浮點數(shù))
- 字符串(在雙引號中)
- 邏輯值(true 或 false)
- 數(shù)組(在方括號中)
- 對象(在花括號中)
- null
- JSONObject
- JSONArray
轉(zhuǎn)載于:https://www.cnblogs.com/onelikeone/p/9999768.html
總結(jié)
- 上一篇: Java核心(三)并发中的线程同步与锁
- 下一篇: JavaScript数组去重算法实例