JSONObject和JSONArray是JDK的集合部分延伸

我一直以爲JSONObject和JSONArray是JDK集合部分的延伸,它們與JDK的List和Map一脈相承。經過研究JSONObject和JSONArray的結構,咱們順便也複習一下JDK的內容。
首先看一下JSONObject和JSONArray 的結構:ide

1 final class JSONObject extends AbstractJSON implements JSON, Map, Comparable
2 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接口:spa

 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接口:code

1 interface List<E> extends Collection<E>
2 Interface Collection<E> extends Iterable<E>
View Code

在List接口中要注意:blog

1 ListIterator<E> listIterator();
2 ListIterator<E> listIterator(int index);
View Code
相關文章
相關標籤/搜索