JSON Sample

http://www.developerfeed.com/json/tutorial/json-sample

http://json.org/example.html

 

Let's see how the data is encoded in JSON, for this consider that we have a entity called Customer, which has name, age, country of residence and two telephone numbers. This information if represented in XML could look something like this:

<customer>
    <name>Mr A</name>
    <age><33/age>
    <country>USA</country>
    <tel>11111111</tel>
    <tel>99999999</tel>
 </customer>

Here name, age and country are represented as Name Value Pairs and tel is an Array of one or more than one telephone the customer has. This same information can be represented in JSON format as:

{"customer":{
"name":"Mr A",
"age":"33",
"country":"USA",
"tel":["111111111","9999999999"]
}}

If there were mutliple customers then it could have been represented as:

<customers>
    <customer>
        <name>Mr A</name>
        <age>33</age>
        <country>USA</country>
        <tel>11111111</tel>
        <tel>99999999</tel>
     </customer>
     <customer>
        <name>Mr B</name>
        <age>22</age>
        <country>USA</country>
        <tel>2222222222</tel>
        <tel>4444444444</tel>
     </customer>
 </customers>

Now here customers is a array(collection) of customer and can be represented in JSON as:

{"customers":
    {"customer":[
        {"name":"Mr A",
        "age":"33",
        "country":"USA",
        "tel":["111111111","9999999999"]},
        {"name":"Mr B",
        "age":"22",
        "country":"USA",
        "tel":["2222222222","44444444"]}
        ]
    }
}

Some more example from JSON.org

{"menu": {
  "id": "file",
  "value": "File",
  "popup": {
    "menuitem": [
      {"value": "New", "onclick": "CreateNewDoc()"},
      {"value": "Open", "onclick": "OpenDoc()"},
      {"value": "Close", "onclick": "CloseDoc()"}
    ]
  }
}}

The same text expressed as XML:

<menu id="file" value="File">
  <popup>
    <menuitem value="New" onclick="CreateNewDoc()" />
    <menuitem value="Open" onclick="OpenDoc()" />
    <menuitem value="Close" onclick="CloseDoc()" />
  </popup>
</menu>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值