public class JSONArray extends Object implements JSON, JSONGetter<Integer>, List<Object>, RandomAccess
["a", "b", "c", 12]
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_CAPACITY
默认初始大小
|
| Constructor and Description |
|---|
JSONArray()
构造
默认使用 ArrayList 实现 |
JSONArray(int initialCapacity)
构造
默认使用 ArrayList 实现 |
JSONArray(int initialCapacity,
JSONConfig config)
构造
默认使用 ArrayList 实现 |
JSONArray(JSONConfig config)
构造
默认使用 ArrayList 实现 |
JSONArray(Object object)
从对象构造,忽略
null的值支持以下类型的参数: 1. |
JSONArray(Object object,
JSONConfig jsonConfig)
从对象构造
支持以下类型的参数: 1. |
JSONArray(Object object,
JSONConfig jsonConfig,
Predicate<Mutable<Object>> predicate)
从对象构造
支持以下类型的参数: 1. |
| Modifier and Type | Method and Description |
|---|---|
void |
add(int index,
Object element) |
boolean |
add(Object e) |
boolean |
add(Object e,
Predicate<Mutable<Object>> predicate)
增加元素
|
boolean |
addAll(Collection<?> c) |
boolean |
addAll(int index,
Collection<?> c) |
protected boolean |
addRaw(Object obj,
Predicate<Mutable<Object>> predicate)
原始添加,添加的对象不做任何处理
|
void |
clear() |
Object |
clone() |
JSONConfig |
config()
获取JSON配置
|
boolean |
contains(Object o) |
boolean |
containsAll(Collection<?> c) |
boolean |
equals(Object obj) |
Object |
get(int index) |
Object |
getObj(Integer index,
Object defaultValue) |
int |
hashCode() |
int |
indexOf(Object o) |
boolean |
isEmpty() |
Iterator<Object> |
iterator() |
String |
join(String separator)
JSONArray转为以
separator为分界符的字符串 |
Iterable<JSONObject> |
jsonIter()
当此JSON列表的每个元素都是一个JSONObject时,可以调用此方法返回一个Iterable,便于使用foreach语法遍历
|
int |
lastIndexOf(Object o) |
ListIterator<Object> |
listIterator() |
ListIterator<Object> |
listIterator(int index) |
JSONArray |
put(int index,
Object value)
加入或者替换JSONArray中指定Index的值,如果index大于JSONArray的长度,将在指定index设置值,之前的位置填充JSONNull.Null
|
JSONArray |
put(Object value)
Append an object value.
|
Object |
remove(int index) |
boolean |
remove(Object o) |
boolean |
removeAll(Collection<?> c) |
boolean |
retainAll(Collection<?> c) |
Object |
set(int index,
Object element)
加入或者替换JSONArray中指定Index的值,如果index大于JSONArray的长度,将在指定index设置值,之前的位置填充JSONNull.Null
|
Object |
set(int index,
Object element,
Predicate<MutableEntry<Integer,Object>> filter)
加入或者替换JSONArray中指定Index的值,如果index大于JSONArray的长度,将在指定index设置值,之前的位置填充JSONNull.Null
|
JSONArray |
set(Object value)
Append an object value.
|
JSONArray |
setDateFormat(String format)
设置转为字符串时的日期格式,默认为时间戳(null值)
|
int |
size()
JSON大小,对于JSONObject,是键值对的多少,JSONArray则是元素的个数
|
List<Object> |
subList(int fromIndex,
int toIndex) |
Object[] |
toArray() |
Object |
toArray(Class<?> arrayClass)
转为Bean数组
|
<T> T[] |
toArray(T[] a) |
JSONObject |
toJSONObject(JSONArray names)
根据给定名列表,与其位置对应的值组成JSONObject
|
String |
toJSONString(int indentFactor,
Predicate<MutableEntry<Object,Object>> predicate)
返回JSON字符串
支持过滤器,即选择哪些字段或值不写出 |
<T> List<T> |
toList(Class<T> elementType)
|
String |
toString()
转为JSON字符串,无缩进
|
Writer |
write(Writer writer,
int indentFactor,
int indent,
Predicate<MutableEntry<Object,Object>> predicate)
将JSON内容写入Writer
Warning: This method assumes that the data structure is acyclical. |
finalize, getClass, notify, notifyAll, wait, wait, waitconvert, getByPath, getByPath, putByPath, toBean, toJSONString, toStringPretty, writeget, getBean, getBeanList, getJSONArray, getJSONObject, getStrEscaped, getStrEscaped, isNullget, get, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBool, getBool, getByte, getByte, getBytes, getBytes, getChar, getChar, getDate, getDate, getDouble, getDouble, getEnum, getEnum, getFloat, getFloat, getInt, getInt, getLocalDate, getLocalDate, getLocalDateTime, getLocalDateTime, getLocalTime, getLocalTime, getLong, getLong, getNumber, getNumber, getObj, getShort, getShort, getSqlTime, getSqlTime, getSqlTimestamp, getSqlTimestamp, getStr, getStrreplaceAll, sort, spliteratorparallelStream, removeIf, streampublic static final int DEFAULT_CAPACITY
public JSONArray()
ArrayList 实现public JSONArray(int initialCapacity)
ArrayList 实现initialCapacity - 初始大小public JSONArray(JSONConfig config)
ArrayList 实现config - JSON配置项public JSONArray(int initialCapacity,
JSONConfig config)
ArrayList 实现initialCapacity - 初始大小config - JSON配置项public JSONArray(Object object) throws JSONException
object - 数组或集合或JSON数组字符串JSONException - 非数组或集合public JSONArray(Object object, JSONConfig jsonConfig) throws JSONException
1. 数组
2. Iterable对象
3. JSON数组字符串
object - 数组或集合或JSON数组字符串jsonConfig - JSON选项JSONException - 非数组或集合public JSONArray(Object object, JSONConfig jsonConfig, Predicate<Mutable<Object>> predicate) throws JSONException
1. 数组
2. Iterable对象
3. JSON数组字符串
object - 数组或集合或JSON数组字符串jsonConfig - JSON选项predicate - 键值对过滤编辑器,可以通过实现此接口,完成解析前对值的过滤和修改操作,null表示不过滤,Predicate.test(Object)为true保留JSONException - 非数组或集合public JSONConfig config()
JSONconfig in interface JSONconfig in interface JSONGetter<Integer>JSONConfigpublic JSONArray setDateFormat(String format)
format - 格式,null表示使用时间戳public String join(String separator) throws JSONException
separator为分界符的字符串separator - 分界符JSONException - If the array contains an invalid number.public Object getObj(Integer index, Object defaultValue)
getObj in interface TypeGetter<Integer>public JSONArray put(Object value)
add(Object)value - 值,可以是: Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the JSONNull.NULL。set(Object)public JSONArray set(Object value)
add(Object)value - 值,可以是: Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the JSONNull.NULL。public JSONArray put(int index, Object value) throws JSONException
index - 位置value - 值对象. 可以是以下类型: Boolean, Double, Integer, JSONArray, JSONObject, Long, String, or the JSONNull.NULL.JSONException - index < 0 或者非有限的数字set(int, Object)public JSONObject toJSONObject(JSONArray names) throws JSONException
names - 名列表,位置与JSONArray中的值位置对应JSONException - 如果任何一个名为nullpublic int hashCode()
public boolean equals(Object obj)
public Iterable<JSONObject> jsonIter()
public int size()
JSONpublic boolean isEmpty()
public boolean contains(Object o)
public Object[] toArray()
public <T> T[] toArray(T[] a)
public boolean add(Object e)
public boolean add(Object e, Predicate<Mutable<Object>> predicate)
e - 元素对象,自动根据对象类型转换为JSON中的对象predicate - 键值对过滤编辑器,可以通过实现此接口,完成解析前对值的过滤和修改操作,null表示不过滤,Predicate.test(Object)为true保留public boolean remove(Object o)
public boolean containsAll(Collection<?> c)
containsAll in interface Collection<Object>containsAll in interface List<Object>public boolean addAll(Collection<?> c)
public boolean addAll(int index,
Collection<?> c)
public boolean removeAll(Collection<?> c)
public boolean retainAll(Collection<?> c)
public void clear()
public Object set(int index, Object element)
public Object set(int index, Object element, Predicate<MutableEntry<Integer,Object>> filter)
index - 位置element - 值对象. 可以是以下类型: Boolean, Double, Integer, JSONArray, JSONObject, Long, String, or the JSONNull.NULL.filter - 过滤器,可以修改值,key(index)无法修改,Predicate.test(Object)为true保留,null表示全部保留。public int lastIndexOf(Object o)
lastIndexOf in interface List<Object>public ListIterator<Object> listIterator()
listIterator in interface List<Object>public ListIterator<Object> listIterator(int index)
listIterator in interface List<Object>public Object toArray(Class<?> arrayClass)
arrayClass - 数组元素类型public <T> List<T> toList(Class<T> elementType)
T - 元素类型elementType - 元素类型ArrayListpublic String toString()
public String toJSONString(int indentFactor, Predicate<MutableEntry<Object,Object>> predicate)
indentFactor - 每层缩进空格数predicate - 过滤器,可以修改值,key(index)无法修改,Predicate.test(Object)为true保留public Writer write(Writer writer, int indentFactor, int indent, Predicate<MutableEntry<Object,Object>> predicate) throws JSONException
JSONwrite in interface JSONwriter - writerindentFactor - 缩进因子,定义每一级别增加的缩进量indent - 本级别缩进量predicate - 过滤器,可以修改值,key(index)无法修改,Predicate.test(Object)为true保留JSONException - JSON相关异常public Object clone() throws CloneNotSupportedException
clone in class ObjectCloneNotSupportedExceptionprotected boolean addRaw(Object obj, Predicate<Mutable<Object>> predicate)
obj - 添加的对象predicate - 键值对过滤编辑器,可以通过实现此接口,完成解析前对值的过滤和修改操作,null表示不过滤,Predicate.test(Object)为true保留Copyright © 2024. All rights reserved.