鍵類型:
必須是 字串
實值型別:
可以是 字串 數字 boolean 對象 數組 空值
e.g. "hello"
e.g. 100.0
e.g. true
e.g. {"a":1, "b":"val_string", "c":true}
e.g. ["a", "b", "c", 100.0, true]
e.g. null
對象:
大括弧包圍的 索引值對的無序組合
{"a":1, "b":true, "c":"c_str", "prev_a":{"a":1, "b":2, "c":3}, "d":100.0}
數組:
中括弧包圍的 實值型別的順序組合
["a", "b", "c", true, 100.0, null, {"a":1, "b":2, "c":3}, [1, 2, 3, "a", "b", "c"]]
參考文獻:
http://www.json.org/
java版本的json解析包(來自json.org網站的原始碼),(另存新檔, 再重新命名為json-parser-v1.0.jar)
http://hi.csdn.net/attachment/201107/19/0_13110714569ee8.gif
主要類:
1) JSONObject 常用方法:
- names(), 擷取鍵的集合;
- optString(String args), 擷取鍵args指定的 字串類型 的值;
- optInt(String args), 擷取 整型的 值;
- optJSONObject(String args), 擷取JSONObject, 遞迴解析;
- optJSONArray(String args), 擷取JSONArray數組,遍曆;
2) JSONArray 常用方法:
- length(), 數組個數
- optString(int index), 擷取索引index位置的,字串類型的值;
- optJSONObject(int index), 擷取JSONObject對象,遞迴解析;
- optJSONArray(int index), 擷取數組,遞迴遍曆