写在WCF实现RESTFul Web Service之前(一):JSON基本概念

JSON基本概念:
WIKIPEDIA : JSON (JavaScript Object Notation), is a lightweight text-based open standard designed for human-readable data interchange. It is derived from the JavaScript scripting language for representing simple data structures and associative arrays, called objects. Despite its relationship to JavaScript, it is language-independent, with parsers available for most languages.
The JSON format is often used for serializing and transmitting structured data over a network connection. It is used primarily to transmit data between a server and web application, serving as an alternative to XML.

JSON是一种轻量级的数据交换格式。易于人阅读和编写,也易于机器解析和生成。JSON采用独立于语言的文本格式,但是也使用了类似C语言家族的习惯(包括C, C++, C#, Java, JavaScript等)。这些特性使JSON成为理想的数据交换语言。很多语言或库对JSON格式有非常好的支持,能方便的进行各种解析和操作。

 

JSON基于两种结构:
1. 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.
2. An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.

 

JSON支持的格式规则:
Number  (type not specified, but in practice double precision floating-point format, as this is how JavaScript in Web browsers treats it)
String    (double-quoted Unicode (UTF-8 by default), with backslash escaping)
Boolean (true or false)
Array     (an ordered sequence of values, comma-separated and enclosed in square brackets; the values do not need to be of the same type)
Object   (an unordered collection of key:value pairs with the ':' character separating the key and the value, comma-separated and enclosed in curly braces; the keys must be strings and should be distinct from each other)
null       (empty)

 

JSON格式数据举例:
The following example shows the JSON representation of an object that describes a person. The object has string fields for first name and last name, a number field for age, contains an object representing the person's address, and contains a list (an array) of phone number objects.

JSON Sample
{
"firstName": "John",
"lastName" : "Smith",
"age" : 25,
"address" :
{
"streetAddress": "21 2nd Street",
"city" : "New York",
"state" : "NY",
"postalCode" : "10021"
},
"phoneNumber":
[
{
"type" : "home",
"number": "212 555-1234"
},
{
"type" : "fax",
"number": "646 555-4567"
}
]
}

 

你可能感兴趣的:(web Service)