![]() |
介紹 JSON |
- object
- {}
{ members } -
- members
- pair
pair , members - pair
- string : value
- array
- []
[ elements ] - elements
- value
value , elements - value
- string
number
object
array
true
false
null
- string
- ""
" chars " - chars
- char
char chars - char
- any-Unicode-character-
except-"-or-\-or-
control-character
\"
\\
\/
\b
\f
\n
\r
\t
\u four-hex-digits - number
- int
int frac
int exp
int frac exp - int
- digit
digit1-9 digits
- digit
- digit1-9 digits - frac
- . digits
- exp
- e digits
- digits
- digit
digit digits - e
- e
e+
e-
E
E+
E-
JSON(JavaScript Object Notation) 是一種輕量級的數(shù)據(jù)交換格式。易于人閱讀和編寫。同時也易于機器解析和生成。它基于JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999的一個子集。 JSON采用完全獨立于語言的文本格式,但是也使用了類似于C語言家族的習(xí)慣(包括C, C++, C#, Java, JavaScript, Perl, Python等)。這些特性使JSON成為理想的數(shù)據(jù)交換語言。
JSON建構(gòu)于兩種結(jié)構(gòu):
- “名稱/值”對的集合(A collection of name/value pairs)。不同的語言中,它被理解為對象(object),紀錄(record),結(jié)構(gòu)(struct),字典(dictionary),哈希表(hash table),有鍵列表(keyed list),或者關(guān)聯(lián)數(shù)組 (associative array)。
- 值的有序列表(An ordered list of values)。在大部分語言中,它被理解為數(shù)組(array)。
這些都是常見的數(shù)據(jù)結(jié)構(gòu)。事實上大部分現(xiàn)代計算機語言都以某種形式支持它們。這使得一種數(shù)據(jù)格式在同樣基于這些結(jié)構(gòu)的編程語言之間交換成為可能。
JSON具有以下這些形式:
對象是一個無序的“‘名稱/值’對”集合。一個對象以“{”(左括號)開始,“}”(右括號)結(jié)束。每個“名稱”后跟一個“:”(冒號);“‘名稱/值’ 對”之間使用“,”(逗號)分隔。
數(shù)組是值(value)的有序集合。一個數(shù)組以“[”(左中括號)開始,“]”(右中括號)結(jié)束。值之間使用“,”(逗號)分隔。
值(value)可以是雙引號括起來的字符串(string)、數(shù)值(number)、true
、false
、 null
、對象(object)或者數(shù)組(array)。這些結(jié)構(gòu)可以嵌套。
字符串(string)是由雙引號包圍的任意數(shù)量Unicode字符的集合,使用反斜線轉(zhuǎn)義。一個字符(character)即一個單獨的字符串(character string)。
字符串(string)與C或者Java的字符串非常相似。
數(shù)值(number)也與C或者Java的數(shù)值非常相似。除去未曾使用的八進制與十六進制格式。除去一些編碼細節(jié)。
空白可以加入到任何符號之間。 以下描述了完整的語言。
- Erlang.
- Haskell:
- Java:
- JavaScript.
- Lasso.
- Lisp:
- LotusScript.
- Lua:
- Objective C.
- Objective CAML.
- OpenLaszlo.
- Perl.
- PHP:
- Pike:
- pl/sql.
- PowerShell.
- Prolog.
- Python:
- R.
- REALbasic.
- Rebol.
- Ruby.
- Squeak.
Why JSON isn't just for JavaScript • I can't believe it's not XML! • The JSON vs XML debate begins in earnest • JSON and XML • Why JSON vs XML is a yawn • JSON vs. XML as a data interchange format • Examining JSON • JSON and .Net • An Introduction to JSON • Shaping the future of secure Ajax mashups • JSON and Browser Security