JSONObject和JSONArray源码整理

花括号,里面key:value

1、pom.xml中需要配置fastjson

 

JSON是抽象类

JSONObject继承JSON,实现了Map<String,Object>


JSONObject类

public class JSONObject

extends JSON implements Map<String, Object>, Cloneable, Serializable, InvocationHandler

 

构造方法:

public JSONObject()

public JSONObject(Map<String, Object> map)

public JSONObject(boolean ordered)

....

普通方法:

1、Map接口中常用方法:

public int size()

public boolean isEmpty()

public boolean containsKey(Object key)

public Object get(Object key)

public Object put(String key, Object value)

public void putAll(Map<? extends String, ? extends Object> m)

public void clear()

public Object remove(Object key)

public Set<String> keySet()

public Collection<Object> values()

public Set<Map.Entry<String, Object>> entrySet()

public Object clone()

public boolean equals(Object obj)

public int hashCode()

2、自己的:

public JSONObject getJSONObject(String key)

public JSONArray getJSONArray(String key)

public <T> T getObject(String key, Class<T> clazz)

public Boolean getBoolean(String key)

public byte[] getBytes(String key)

public boolean getBooleanValue(String key)

public Byte getByte(String key)

public Integer getInteger(String key)

public int getIntValue(String key)

public Date getDate(String key)

public java.sql.Date getSqlDate(String key)

public Map<String, Object> getInnerMap()

........


JSONArray类

public class JSONArray

extends JSON implements List<Object>, Cloneable, RandomAccess, Serializable

 

构造方法:

public JSONArray()

public JSONArray(List<Object> list)

public JSONArray(int initialCapacity)

普通方法:

1、List接口中方法:

public int size()

public boolean isEmpty()

public boolean contains(Object o)

public Iterator<Object> iterator()

public Object[] toArray()

public <T> T[] toArray(T[] a)

public boolean add(Object e)

public boolean remove(Object o)

public boolean containsAll(Collection<?> c)

public boolean addAll(Collection<? extends Object> c)

public boolean addAll(int index, Collection<? extends Object> c)

public void clear()

public Object set(int index, Object element)

public void add(int index, Object element)

public Object remove(int index)

public int indexOf(Object o)

public int lastIndexOf(Object o)

public List<Object> subList(int fromIndex, int toIndex)

public Object get(int index)

public Object clone()

public boolean equals(Object obj)

public int hashCode()

2、自己的:

public JSONObject getJSONObject(int index)

public JSONArray getJSONArray(int index)

public <T> T getObject(int index, Class<T> clazz)

public <T> T getObject(int index, Type type)

public Boolean getBoolean(int index)

public boolean getBooleanValue(int index)

public Byte getByte(int index)

public byte getByteValue(int index)

public Short getShort(int index)

public short getShortValue(int index)

public Integer getInteger(int index)

public int getIntValue(int index)

public Long getLong(int index)

public long getLongValue(int index)

public String getString(int index)

public java.util.Date getDate(int index)

public java.sql.Date getSqlDate(int index)

public java.sql.Timestamp getTimestamp(int index)

public <T> List<T> toJavaList(Class<T> clazz)


JSON类(抽象类)

public abstract class JSON implements JSONStreamAware, JSONAware

 

常用方法:

public static Object parse(String text)

public static JSONObject parseObject(String text)

public static JSONArray parseArray(String text)

public static <T> List<T> parseArray(String text, Class<T> clazz)

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值