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"
         }
     ]
 }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值