public class JSONArray extends JSONGetter<Integer> implements JSON, List<Object>, RandomAccess
["a", "b", "c", 12]
| 限定符和类型 | 字段和说明 |
|---|---|
static int |
DEFAULT_CAPACITY
默认初始大小
|
| 构造器和说明 |
|---|
JSONArray()
构造
默认使用 ArrayList 实现 |
JSONArray(CharSequence source)
从String构造(JSONArray字符串)
|
JSONArray(Collection<Object> list)
构造
将参数数组中的元素转换为JSON对应的对象加入到JSONArray中 |
JSONArray(int initialCapacity)
构造
默认使用 ArrayList 实现 |
JSONArray(int initialCapacity,
JSONConfig config)
构造
默认使用 ArrayList 实现 |
JSONArray(Iterable<Object> list)
构造
将参数数组中的元素转换为JSON对应的对象加入到JSONArray中 |
JSONArray(JSONConfig config)
构造
默认使用 ArrayList 实现 |
JSONArray(JSONTokener x)
使用
JSONTokener 做为参数构造 |
JSONArray(Object object)
从对象构造,忽略
null的值支持以下类型的参数: 1. |
JSONArray(Object object,
boolean ignoreNullValue)
从对象构造
支持以下类型的参数: 1. |
JSONArray(Object object,
JSONConfig jsonConfig)
从对象构造
支持以下类型的参数: 1. |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
add(int index,
Object element) |
boolean |
add(Object e) |
boolean |
addAll(Collection<?> c) |
boolean |
addAll(int index,
Collection<?> c) |
void |
clear() |
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 获取表达式对应值后转换为对应类型的值 |
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.
|
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 |
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)
转为JSON字符串,指定缩进值
|
<T> List<T> |
toList(Class<T> elementType)
|
String |
toString()
转为JSON字符串,无缩进
|
String |
toStringPretty()
格式化打印JSON,缩进为4个空格
|
Writer |
write(Writer writer)
将JSON内容写入Writer,无缩进
Warning: This method assumes that the data structure is acyclical. |
Writer |
write(Writer writer,
int indentFactor,
int indent)
将JSON内容写入Writer
Warning: This method assumes that the data structure is acyclical. |
get, get, getBean, getJSONArray, getJSONObject, getStrEscaped, getStrEscaped, isNullgetBigDecimal, getBigInteger, getBool, getByte, getChar, getDate, getDouble, getEnum, getFloat, getInt, getLong, getShort, getStrgetBigDecimal, getBigInteger, getBool, getByte, getChar, getDate, getDouble, getEnum, getFloat, getInt, getLong, getObj, getShort, getStrpublic 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(Iterable<Object> list)
list - 初始化的JSON数组public JSONArray(Collection<Object> list)
list - 初始化的JSON数组public JSONArray(JSONTokener x) throws JSONException
JSONTokener 做为参数构造x - A JSONTokenerJSONException - If there is a syntax error.public JSONArray(CharSequence source) throws JSONException
source - JSON数组字符串JSONException - If there is a syntax error.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 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 在接口中 OptBasicTypeGetter<Integer>getObj 在类中 OptNullBasicTypeFromObjectGetter<Integer>public Object getByPath(String expression)
JSONpersion persion.name persons[3] person.friends[5].name
getByPath 在接口中 JSONexpression - 表达式BeanPath.get(Object)public <T> T getByPath(String expression, Class<T> resultType)
JSONpersion persion.name persons[3] person.friends[5].name获取表达式对应值后转换为对应类型的值
getByPath 在接口中 JSONT - 返回值类型expression - 表达式resultType - 返回值类型BeanPath.get(Object)public void putByPath(String expression, Object value)
JSONpersion 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。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 或者非有限的数字public JSONObject toJSONObject(JSONArray names) throws JSONException
names - 名列表,位置与JSONArray中的值位置对应JSONException - 如果任何一个名为nullpublic int hashCode()
public boolean equals(Object obj)
public Iterable<JSONObject> jsonIter()
public boolean isEmpty()
public boolean contains(Object o)
public Object[] toArray()
public <T> T[] toArray(T[] a)
public boolean remove(Object o)
public boolean containsAll(Collection<?> c)
containsAll 在接口中 Collection<Object>containsAll 在接口中 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 int lastIndexOf(Object o)
lastIndexOf 在接口中 List<Object>public ListIterator<Object> listIterator()
listIterator 在接口中 List<Object>public ListIterator<Object> listIterator(int index)
listIterator 在接口中 List<Object>public <T> List<T> toList(Class<T> elementType)
T - 元素类型elementType - 元素类型ArrayListpublic String toStringPretty() throws JSONException
toStringPretty 在接口中 JSONJSONException - 包含非法数抛出此异常public String toJSONString(int indentFactor) throws JSONException
toJSONString 在接口中 JSONindentFactor - 缩进值,即缩进空格数JSONException - JSON写入异常public Writer write(Writer writer) throws JSONException
JSONwrite 在接口中 JSONwriter - WriterJSONException - JSON相关异常public Writer write(Writer writer, int indentFactor, int indent) throws JSONException
JSONwrite 在接口中 JSONwriter - writerindentFactor - 缩进因子,定义每一级别增加的缩进量indent - 本级别缩进量JSONException - JSON相关异常Copyright © 2019. All rights reserved.