2011年8月6日 星期六

[Format] JSON

* Definition
  • JSON: Javascript Object Notation
  • 輕量級的資料交換語言,以文字為基礎,且易於讓人閱讀。
  • 儘管JSON是在Javascript的一個子集,但JSON是獨立於語言的文字格式,並且採用了類似於C語言家族的一些習慣。
  • 幾乎所有與網頁開發相關的語言都有JSON函式庫。
  • JSON與XML最大的不同在於XML是一個完整的標記語言,而JSON不是。
    • 這使的XML在程式判讀上需要比較多的功夫。主要的原因在於XML的設計理念與JSON不同。
    • XML
      • Easy extensible.
        • XML利用標記語言的特性提供了絕佳的延展性(如XPath),在資料儲存,擴充功能及高階檢索方面具備對JSON的優勢。
    • JSON
      • More faster when using.
        • JSON則由於比XML更加小巧,以及瀏覽器的內建快速解析支援,使得其更適用於網路資料傳輸領域。
      • More Security
        • 由於Javascript採用了稱為「沙盒」的機制,這種機制限制Javascript引擎僅能引入同一個站點的代碼,因而某種程度上提高了安全性

* Java API
  • key is case sensitive.
  • A get method returns a value if one can be found, and throws an exception if one cannot be found.
  • The generic get() and opt() methods return an object, which you can cast or query for type
    • There are also typed get and opt methods that do type checking and type coercion for you. 
    • The opt methods differ from the get methods in that they do not throw. Instead, they return a specified value, such as null.
  • Strings do not need to be quoted at all if... 
    • they do not begin with a quote or single quote, 
    • they do not contain leading or trailing spaces, 
    • they do not contain any of these characters: { } [ ] / \ : , = ; # 
    • they do not look like numbers and if they are not the reserved words true, false, or null.

* Reference
- 介绍 JSON : Have JSON format figures.
- wiki JSON : Have JSON examples.
- RFC 4627
- JSON : Explain with Javascript.
- JSON 速寫 : Javascript syntax example.
- Class JSONObject **
- android开发中文文档之基于JSON数据交换应用

沒有留言:

張貼留言