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,
boolean ignoreNullValue)
从对象构造
支持以下类型的参数: 1. |
JSONArray(Object object,
JSONConfig jsonConfig)
从对象构造
支持以下类型的参数: 1. |
JSONArray(Object object,
JSONConfig jsonConfig,
Filter<Mutable<Object>> filter)
从对象构造
支持以下类型的参数: 1. |
| Modifier and Type | Method and Description |
|---|---|
void |
add(int index,
Object element) |
boolean |
add(Object e) |
boolean |
addAll(Collection<?> c) |
boolean |
addAll(int index,
Collection<?> c) |
protected boolean |
addRaw(Object obj,
Filter<Mutable<Object>> filter)
原始添加,添加的对象不做任何处理
|
void |
clear() |
Object |
clone() |
boolean |
contains(Object o) |
boolean |
containsAll(Collection<?> c) |
boolean |
equals(Object obj) |
Object |
get(int index) |
Object |
getByPath(String expression)
通过表达式获取JSON中嵌套的对象
.表达式,可以获取Bean对象中的属性(字段)值或者Map中key对应的值 []表达式,可以获取集合等对象中对应index的值 表达式栗子: persion persion.name persons[3] person.friends[5].name |
<T> T |
getByPath(String expression,
Class<T> resultType)
通过表达式获取JSON中嵌套的对象
.表达式,可以获取Bean对象中的属性(字段)值或者Map中key对应的值 []表达式,可以获取集合等对象中对应index的值 表达式栗子: persion persion.name persons[3] person.friends[5].name 获取表达式对应值后转换为对应类型的值 |
<T> T |
getByPath(String expression,
TypeReference<T> targetType)
通过表达式获取JSON中嵌套的对象
.表达式,可以获取Bean对象中的属性(字段)值或者Map中key对应的值 []表达式,可以获取集合等对象中对应index的值 表达式栗子: persion persion.name persons[3] person.friends[5].name 获取表达式对应值后转换为对应类型的值 |
JSONConfig |
getConfig()
获取JSON配置
|
Object |
getObj(Integer index,
Object defaultValue)
获取Object属性值
|
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.
|
void |
putByPath(String expression,
Object value)
设置表达式指定位置(或filed对应)的值
若表达式指向一个JSONArray则设置其坐标对应位置的值,若指向JSONObject则put对应key的值 注意:如果为JSONArray,设置值下标小于其长度,将替换原有值,否则追加新值 .表达式,可以获取Bean对象中的属性(字段)值或者Map中key对应的值 []表达式,可以获取集合等对象中对应index的值 表达式栗子: persion persion.name persons[3] person.friends[5].name |
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,
Filter<MutablePair<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() |
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,
Filter<MutablePair<Object,Object>> filter)
返回JSON字符串
支持过滤器,即选择哪些字段或值不写出 |
<T> List<T> |
toList(Class<T> elementType)
|
String |
toString()
转为JSON字符串,无缩进
|
Writer |
write(Writer writer,
int indentFactor,
int indent)
将JSON内容写入Writer
Warning: This method assumes that the data structure is acyclical. |
Writer |
write(Writer writer,
int indentFactor,
int indent,
Filter<MutablePair<Object,Object>> filter)
将JSON内容写入Writer
支持过滤器,即选择哪些字段或值不写出 |
finalize, getClass, notify, notifyAll, wait, wait, waittoBean, toBean, toBean, toBean, toJSONString, toStringPretty, writeget, get, getBean, getBeanList, getBytes, getDate, getJSONArray, getJSONObject, getLocalDateTime, getStrEscaped, getStrEscaped, isNullgetBigDecimal, getBigInteger, getBool, getByte, getChar, getDouble, getEnum, getFloat, getInt, getLong, getShort, getStrgetBigDecimal, getBigInteger, getBool, getByte, getChar, getDate, getDouble, getEnum, getFloat, getInt, getLong, getObj, getShort, 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, boolean ignoreNullValue) throws JSONException
1. 数组
2. Iterable对象
3. JSON数组字符串
object - 数组或集合或JSON数组字符串ignoreNullValue - 是否忽略空值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, Filter<Mutable<Object>> filter) throws JSONException
1. 数组
2. Iterable对象
3. JSON数组字符串
object - 数组或集合或JSON数组字符串jsonConfig - JSON选项filter - 键值对过滤编辑器,可以通过实现此接口,完成解析前对值的过滤和修改操作,null表示不过滤JSONException - 非数组或集合public JSONConfig getConfig()
JSONgetConfig in interface JSONgetConfig 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)
OptBasicTypeGettergetObj in interface OptBasicTypeGetter<Integer>index - 属性名defaultValue - 默认值public Object getByPath(String expression)
JSON表达式栗子:
persion persion.name persons[3] person.friends[5].name
getByPath in interface JSONexpression - 表达式BeanPath.get(Object)public <T> T getByPath(String expression, Class<T> resultType)
JSON表达式栗子:
persion persion.name persons[3] person.friends[5].name
获取表达式对应值后转换为对应类型的值
getByPath in interface JSONT - 返回值类型expression - 表达式resultType - 返回值类型BeanPath.get(Object)public <T> T getByPath(String expression, TypeReference<T> targetType)
JSON表达式栗子:
persion persion.name persons[3] person.friends[5].name
获取表达式对应值后转换为对应类型的值
getByPath in interface JSONT - 获取对象类型expression - 表达式targetType - 返回值类型BeanPath.get(Object)public void putByPath(String expression, Object value)
JSON表达式栗子:
persion persion.name persons[3] person.friends[5].name
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()
public boolean isEmpty()
public boolean contains(Object o)
public Object[] toArray()
public <T> T[] toArray(T[] a)
public boolean add(Object e)
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, Filter<MutablePair<Integer,Object>> filter)
index - 位置element - 值对象. 可以是以下类型: Boolean, Double, Integer, JSONArray, JSONObject, Long, String, or the JSONNull.NULL.filter - 过滤器,可以修改值,key(index)无法修改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, Filter<MutablePair<Object,Object>> filter)
indentFactor - 每层缩进空格数filter - 过滤器,可以修改值,key(index)无法修改public Writer write(Writer writer, int indentFactor, int indent) throws JSONException
JSONwrite in interface JSONwriter - writerindentFactor - 缩进因子,定义每一级别增加的缩进量indent - 本级别缩进量JSONException - JSON相关异常public Writer write(Writer writer, int indentFactor, int indent, Filter<MutablePair<Object,Object>> filter) throws JSONException
writer - writerindentFactor - 缩进因子,定义每一级别增加的缩进量indent - 本级别缩进量filter - 过滤器,可以修改值,key(index)无法修改JSONException - JSON相关异常public Object clone() throws CloneNotSupportedException
clone in class ObjectCloneNotSupportedExceptionCopyright © 2025. All rights reserved.