之前ajax實作都用XML格式,來傳遞資料,因為對json 不了解,以為json是一種文字無法像xml可以有tag來辨識。

 

後來同事介紹才發現json 也有Tag格式,而且不像xml,Tag一定要成對,傳遞資料量相對也少更多,對ajax來說是非常合適的。

 

以下是json 自己整理網路上資料的總整理,以入門為主

JSON (Javascript Object Notation)

  • 是一種輕量級的資料交換語言,以文字為基礎是附屬在 javascript 下的一組物件描述方法,

 

json規格請看http://zh.wikipedia.org/wiki/JSON

其實看資料展示就知道怎麼用了(phoneNumber內有[]表示是陣列。

{
     "firstName": "John",
     "lastName": "Smith",
     "male": true,
     "age": 25,
     "address": 
     {
         "streetAddress": "21 2nd Street",
         "city": "New York",
         "state": "NY",
         "postalCode": "10021"
     },
     "phoneNumber": 
     [
         {
           "type": "home",
           "number": "12345678"
         },
         {
           "type": "fax",
           "number": "87654321"
         }
     ]
 }

參考網站:

JSON之教學筆記

Introducing JSON

白話說JSON

arrow
arrow
    文章標籤
    ajax json
    全站熱搜

    味味A 發表在 痞客邦 留言(0) 人氣()