首页 > 代码库 > json深度详解及org.json库
json深度详解及org.json库
- 了解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:
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库