標籤:writer zab 研究 key ring isa 技術 pen one
我一直覺得JSONObject和JSONArray是JDK集合部分的延伸,它們與JDK的List和Map一脈相承。通過研究JSONObject和JSONArray的結構,我們順便也複習一下JDK的內容。
首先看一下JSONObject和JSONArray 的結構:
1 final class JSONObject extends AbstractJSON implements JSON, Map, Comparable2 final class JSONArray extends AbstractJSON implements JSON, List, Comparable
View Code
首先看看JSON介面:JSON extends Serializable,這一點表明JSONObject和JSONArray是可以實現序列化的。JSON介面的具體的定義也是針對很常用的功能:
1 boolean isArray();2 boolean isEmpty();3 int size();//對於JSONObject來說是Bean屬性的個數,對於JSONArray來說是Bean的個數4 String toString( int indentFactor );5 String toString( int indentFactor, int indent );6 Writer write( Writer writer );
View Code
接著看一下Map介面:
1 int size(); 2 boolean isEmpty(); 3 boolean containsKey(Object key); 4 boolean containsValue(Object value); 5 V get(Object key); 6 V put(K key, V value); 7 V remove(Object key); 8 void putAll(Map<? extends K, ? extends V> m); 9 void clear();10 Set<K> keySet();11 Collection<V> values();12 Set<Map.Entry<K, V>> entrySet();
View Code
上面的一個函數引出了另外一個介面:Entry<K,V>
再接著看一下List介面:
1 interface List<E> extends Collection<E>2 Interface Collection<E> extends Iterable<E>
View Code
在List介面中要注意:
1 ListIterator<E> listIterator();2 ListIterator<E> listIterator(int index);
View Code
JSONObject和JSONArray是JDK的集合部分延伸