zoukankan      html  css  js  c++  java
  • json学习系列(6)JSONObject和JSONArray是JDK的集合部分延伸

    我一直觉得JSONObject和JSONArray是JDK集合部分的延伸,它们与JDK的List和Map一脉相承。通过研究JSONObject和JSONArray的结构,我们顺便也复习一下JDK的内容。
    首先看一下JSONObject和JSONArray 的结构:

    final class JSONObject extends AbstractJSON implements JSON, Map, Comparable
    final class JSONArray extends AbstractJSON implements JSON, List, Comparable

    首先看看JSON接口:JSON extends Serializable,这一点表明JSONObject和JSONArray是可以实现序列化的。JSON接口的具体的定义也是针对很常用的功能:

    boolean isArray();
    boolean isEmpty();
    int size();//对于JSONObject来说是Bean属性的个数,对于JSONArray来说是Bean的个数
    String toString( int indentFactor );
    String toString( int indentFactor, int indent );
    Writer write( Writer writer );

    接着看一下Map接口:

    int size();
    boolean isEmpty();
    boolean containsKey(Object key);
    boolean containsValue(Object value);
    V get(Object key);
    V put(K key, V value);
    V remove(Object key);
    void putAll(Map<? extends K, ? extends V> m);
    void clear();
    Set<K> keySet();
    Collection<V> values();
    Set<Map.Entry<K, V>> entrySet();

    上面的一个函数引出了另外一个接口:Entry<K,V>
    再接着看一下List接口:

    interface List<E> extends Collection<E>
    Interface Collection<E> extends Iterable<E>

    在List接口中要注意:

    ListIterator<E> listIterator();
    ListIterator<E> listIterator(int index);

    ListIterator接口实现了前后移动的功能。比Iterator接口的功能更强大。

  • 相关阅读:
    2021 6 3
    2021 5月 读书笔记
    2021 6 1
    第十三周 2021.05.30
    spring security permitAll不生效
    springboot配置jpa提示Unable to resolve name [mysql] as strategy
    element el-form-item el-input宽度设置
    vue+element表格中使用render函数(if判断处理)
    elementui移除tab报Avoided redundant navigation to current location: ***
    el-dropdown-item添加@click不生效
  • 原文地址:https://www.cnblogs.com/longshiyVip/p/4608126.html
Copyright © 2011-2022 走看看