json深度詳解及org.json庫

來源:互聯網
上載者:User

標籤:

  • 瞭解json  (Javascript Object Notation)

網站:http://json.org/

 

english


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 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.

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.

In JSON, they take on these forms:

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).

 

 

An array is an ordered collection of values. An array begins with [ (left bracket) and ends with ] (right bracket). Values are separated by , (comma).

 

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.

 

A string is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes. A character is represented as a single character string. A string is very much like a C or Java string.

 

 

 

A number is very much like a C or Java number, except that the octal and hexadecimal formats are not used.

 

Whitespace can be inserted between any pair of tokens. Excepting a few encoding details, that completely describes the language.

中文翻譯


JSON(javascript對象圖)是一種輕量級的數交換格式。它易於人類的讀與寫。易於讓機器解析和產生。它基於javascript語言的子集、standard ECMA-262 第三版。JSON是一個獨立於變成語言的文字格式設定,但是呢慣例上被用於我們熟悉的C語系程式設計語言,比如C,C++,C#,java,javascript,Perl,Python,和其他語言。這些特性使得JSON成為一種理想的資料交換格式語言。



JSON基於兩種格式構建:
        1 基於 名/值對兒的集合,在各種語言裡實現為一個對象,記錄,結構體,指點,雜湊表,一個關鍵列表,或一個關聯陣列。
         ps:在java中 可以理解為map

        2 一個有序的值列表。在大多數語言裡,實現成為一個數組,一個vector,一個列表,或者一個序列。

      這些是一些很常見的資料結構.事實上現代所有的程式設計語言都以一種或者其他形式支援這種編程結構。這樣的意義在於可以基於這樣的結構在各種程式設計語言之間進行交換。


在JSON中,使用以下結構:

一個對象,是一個無需的 名/值對兒。一個對象以花括弧 { 開始,以 } 作為結束標誌。每個名字後面緊跟 : 冒號,名值對兒之間使用逗號 , 來分割。 





一個數組是一個有序的值集合。一個數組以一個方括弧 [ 開始,以右方括弧 ] 結束。各個值之間使用逗號 , 進行分割。




一個值,可以使用雙引號引起來的字串、或一個數字、或一個布爾值 true/false、或null、或一個對象object、或者是一個數組array. 並且這些結構是可以被嵌套的。



一個字串string, 是0或者多個unicode字元構成的,用雙引號包起來,用反斜線 \ 進行轉義。一個字元被表現為長度為1的字串(因為javascript中沒有字元的概念,只有字串),而一個字串則是和C或java語言一樣的String類型。







數字非常類似於C或者java語言中的數字類型,除了八進位和十六進位格式在這裡沒有被用到。

 

json格式中多餘的空格都可以被各種語言正確的理解。

比如:

var s={‘a‘:‘123‘,‘b‘:false};

var s={‘a‘:‘123‘,      ‘b‘:false};//多了一些空格,這樣也是合法的。

   

 

 

javascript中定義的一個對象,就是一種最簡單的json格式

如:

var s={‘a‘:‘123‘,‘b‘:false,‘c‘:undefined,‘d‘:123,‘e‘:null};

var arr=[‘a‘,‘b‘,‘c‘,‘d‘,false];

json深度詳解及org.json庫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.