fastjson文档解读——下篇

来源:互联网 发布:事业单位选调考试软件 编辑:程序博客网 时间:2024/06/18 14:52

com.alibaba.fastjson.JSONArray

有一些基本的数组操作方法,就像操作List数组一样操作JSONArray就可以。

添加元素:

void add(int index, Object element)

boolean add(Object e)

boolean addAll(Collection<? extendsObject> c)

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

获取元素:

Object get(int index)

 

BigDecimal getBigDecimal(int index)

BigInteger getBigInteger(int index)

 

Boolean getBoolean(int index)

boolean getBooleanValue(int index)

 

Byte getByte(int index)

byte getByteValue(int index)

 

Type getComponentType()

 

Date getDate(int index)

 

Double getDouble(int index)

double getDoubleValue(int index)

 

Float getFloat(int index)

float getFloatValue(int index)

 

Integer getInteger(int index)

int getIntValue(int index)

 

JSONArray getJSONArray(int index)

JSONObject getJSONObject(int index)

 

Long getLong(int index)

long getLongValue(int index)

 

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

Object getRelatedArray()

 

Short getShort(int index)

short getShortValue(int index)

 

Date getSqlDate(int index)

 

String getString(int index)

 

Timestamp getTimestamp(int index)

Iterator:

Iterator<Object> iterator()

int lastIndexOf(Object o)

ListIterator<Object> listIterator()

ListIterator<Object> listIterator(intindex)

 

删除:

Object remove(int index)

boolean remove(Object o)

boolean removeAll(Collection<?> c)

boolean retainAll(Collection<?> c)

 

其他重要方法:

void clear():清空数组。即遍历数组,移除其中所有的键值,并置为null。

Object clone():克隆。

Boolean contains(Object o):判断是否包含某个元素。

Boolean containsAll(Collection<?> c):判断是否包含某个集合

Boolean equals(Object obj):判断是否与所传对象相同。equals只比较值。

 

com.alibaba.fastjson.JSONObject

添加元素

Object put (String key, Object value)

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

 

取值:

Object get(Object key)

 

BigDecimal getBigDecimal(String key)

BigInteger getBigInteger(String key)

 

Boolean getBoolean(String key)

boolean getBooleanValue(String key)

 

Byte getByte(String key)

byte[] getBytes(String key)

byte getByteValue(String key)

 

Date getDate(String key)

 

Double getDouble(String key)

double getDoubleValue(String key)

 

Float getFloat(String key)

float getFloatValue(String key)

 

Integer getInteger(String key)

int getIntValue(String key)

 

JSONArray getJSONArray(String key)

JSONObject getJSONObject(String key)

 

Long getLong(String key)

long getLongValue(String key)

 

<T> T getObject(Stringkey,Class<T> clazz)

 

Short getShort(String key)

short getShort(String key)

 

Date getSqlDate(String key)

 

String getString(String key)

 

Timestamp getTimestamp(String key)

 

删除:

Object remove (Object key)

 

其他重要方法:

void clear():清空

Object clone():克隆

boolean containsKey(Object key):是否包含某键

boolean containsValue(Object value):是否包含某值

set<map.Entry<String,Object>>entrySet():取键值对

boolean equals (Object obj):判断是否相等

int hashCode():返回JSONObject对象的hashCode

Object invoke(Object proxy, Method method,Object[] args):

boolean isEmpty():判断是否为空

Set<String> keyset():取键的集合

int size():JSONObject的大小

Collection <Object> values():取值的集合

1 0
原创粉丝点击