Class JSONArray
- All Implemented Interfaces:
Serializable, Cloneable, Iterable<Object>, Collection<Object>, List<Object>, RandomAccess, SequencedCollection<Object>
-
Field Summary
Fields inherited from class AbstractList
modCount -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription深拷贝(嵌套 JSONObject/JSONArray/Map/List 均递归复制)。<T> T读取并转换为 Bean。getBigDecimal(int index) 取 BigDecimal 值(金额场景)。getBigDecimal(int index, BigDecimal defaultValue) 取 BigDecimal 值,越界或转换失败返回默认值。getBigInteger(int index) 取 BigInteger 值。getBigInteger(int index, BigInteger defaultValue) 取 BigInteger 值,越界或转换失败返回默认值。getBool(int index) 读取布尔值,越界返回null。bytegetByte(int index) 取 byte 值。bytegetByte(int index, byte defaultValue) 取 byte 值。chargetChar(int index) 取 char 值。chargetChar(int index, char defaultValue) 取 char 值。getDate(int index) 取日期值(支持时间戳与常见日期字符串,转换失败返回 null)。getDouble(int index) 读取浮点数,越界或无法解析返回null。floatgetFloat(int index) 取 float 值。floatgetFloat(int index, float defaultValue) 取 float 值。getInt(int index) 读取整数,越界或无法解析返回null。getJSONArray(int index) 读取嵌套 JSON 数组。getJSONObject(int index) 读取嵌套 JSON 对象。getLocalDate(int index) 取 LocalDate 值。getLocalDateTime(int index) 取 LocalDateTime 值。getLong(int index) 读取长整数,越界或无法解析返回null。shortgetShort(int index) 取 short 值。shortgetShort(int index, short defaultValue) 取 short 值。getStr(int index) 读取字符串值,越界或为 null 返回null。将数组元素用分隔符拼接。static JSONArray解析 JSON 字符串。<T> T[]转为对象数组(元素为 JSONObject 时按 beanClass 转换)。序列化为 JSON 字符串。<T> List<T> 转为对象列表(元素为 JSONObject 时按 beanClass 转换)。toString()Methods inherited from class ArrayList
add, add, addAll, addAll, addFirst, addLast, clear, clone, contains, ensureCapacity, equals, forEach, get, getFirst, getLast, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeFirst, removeIf, removeLast, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSizeMethods inherited from class AbstractCollection
containsAllMethods inherited from interface Collection
parallelStream, stream, toArrayMethods inherited from interface List
containsAll, reversed
-
Constructor Details
-
JSONArray
public JSONArray()创建空 JSON 数组。 -
JSONArray
-
JSONArray
-
JSONArray
-
-
Method Details
-
parse
-
getStr
读取字符串值,越界或为 null 返回null。- Parameters:
index- 索引- Returns:
- 字符串值或
null
-
getInt
-
getLong
-
getDouble
-
getBool
-
getJSONObject
读取嵌套 JSON 对象。- Parameters:
index- 索引- Returns:
- JSON 对象或
null
-
getJSONArray
读取嵌套 JSON 数组。- Parameters:
index- 索引- Returns:
- JSON 数组或
null
-
getBean
读取并转换为 Bean。- Type Parameters:
T- Bean 类型- Parameters:
index- 索引beanClass- Bean 类- Returns:
- Bean 或
null
-
toJsonString
-
toString
- Overrides:
toStringin classAbstractCollection<Object>
-
getChar
public char getChar(int index) 取 char 值。- Parameters:
index- 下标- Returns:
- char;缺失返回 0
-
getChar
public char getChar(int index, char defaultValue) 取 char 值。- Parameters:
index- 下标defaultValue- 默认值- Returns:
- char;缺失返回默认值
-
getShort
public short getShort(int index) 取 short 值。- Parameters:
index- 下标- Returns:
- short;缺失返回 0
-
getShort
public short getShort(int index, short defaultValue) 取 short 值。- Parameters:
index- 下标defaultValue- 默认值- Returns:
- short;缺失返回默认值
-
getByte
public byte getByte(int index) 取 byte 值。- Parameters:
index- 下标- Returns:
- byte;缺失返回 0
-
getByte
public byte getByte(int index, byte defaultValue) 取 byte 值。- Parameters:
index- 下标defaultValue- 默认值- Returns:
- byte;缺失返回默认值
-
getFloat
public float getFloat(int index) 取 float 值。- Parameters:
index- 下标- Returns:
- float;缺失返回 0
-
getFloat
public float getFloat(int index, float defaultValue) 取 float 值。- Parameters:
index- 下标defaultValue- 默认值- Returns:
- float;缺失返回默认值
-
getDate
取日期值(支持时间戳与常见日期字符串,转换失败返回 null)。- Parameters:
index- 下标- Returns:
- 日期;缺失或转换失败返回 null
-
getLocalDate
取 LocalDate 值。- Parameters:
index- 下标- Returns:
- LocalDate;越界或转换失败返回 null
-
getLocalDateTime
取 LocalDateTime 值。- Parameters:
index- 下标- Returns:
- LocalDateTime;越界或转换失败返回 null
-
getBigDecimal
取 BigDecimal 值(金额场景)。- Parameters:
index- 下标- Returns:
- BigDecimal;缺失或转换失败返回 null
-
getBigDecimal
取 BigDecimal 值,越界或转换失败返回默认值。- Parameters:
index- 下标defaultValue- 默认值- Returns:
- BigDecimal 或默认值
-
getBigInteger
取 BigInteger 值。- Parameters:
index- 下标- Returns:
- BigInteger;越界或转换失败返回 null
-
getBigInteger
取 BigInteger 值,越界或转换失败返回默认值。- Parameters:
index- 下标defaultValue- 默认值- Returns:
- BigInteger 或默认值
-
toList
-
toArray
转为对象数组(元素为 JSONObject 时按 beanClass 转换)。- Type Parameters:
T- 泛型- Parameters:
beanClass- 目标类型- Returns:
- 对象数组
-
deepClone
-
join
-