什麼是JSON格式?

JSON(JavaScript Object Notation)是一種輕量級的語言,以文字為基礎,且易於讓人閱讀。
JSON以key-value的格式儲存資料,並且必須被包在"{"與"}"符號之中。

以訂單內容為範例,JSON與XML不同格式有不同的表示方法:

JSON

{
  "orderID": 12345,
  "shopperName": "John Smith",
  "shopperEmail": "johnsmith@example.com",
  "contents": [
    {
      "productID": 34,
      "productName": "SuperWidget",
      "quantity": 1
    },
    {
      "productID": 56,
      "productName": "WonderWidget",
      "quantity": 3
    }
  ],
  "orderCompleted": true
}

XML 

<object>
  <property>
    <key>orderID</key>
    <number>12345</number>
  </property>
  <property>
    <key>shopperName</key>
    <string>John Smith</string>
  </property>
  <property>
    <key>shopperEmail</key>
    <string>johnsmith@example.com</string>
  </property>
  <property>
    <key>contents</key>
    <array>
      <object>
        <property>
          <key>productID</key>
          <number>34</number>
        </property>
        <property>
          <key>productName</key>
          <string>SuperWidget</string>
        </property>
        <property>
          <key>quantity</key>
          <number>1</number>
        </property>       
      </object>
      <object>
        <property>
          <key>productID</key>
          <number>56</number>
        </property>
        <property>
          <key>productName</key>
          <string>WonderWidget</string>
        </property>
        <property>
          <key>quantity</key>
          <number>3</number>
        </property>
      </object>
    </array>
  </property>
  <property>
    <key>orderCompleted</key>
    <boolean>true</boolean>
  </property> 
</object>

JSON和XML的不同 XML是標記語言,需要費更大的功夫才能解讀,XML在容易資料儲存方面更具優勢,而JSON輕巧的特性,使其較適合用於資料傳輸。

reference

瞭解JSON格式 @ 清新下午茶 :: 痞客邦 PIXNET ::
你不可不知的 JSON 基本介紹 | 小惡魔 - 電腦技術 - 工作筆記 - AppleBOY

1 則留言:

  1. titanium flash mica | TITanium Sports
    Titanium flash mica is a new and innovative device, made by TPC mens titanium earrings Gaming, Limited, for ford focus titanium hatchback the mobile gaming and gaming market. titanium necklace This ceramic or titanium flat iron new used ford edge titanium device was developed by

    回覆刪除