/**
* JSON字符串转JSONArray
* @param arrayOrCollection 数组或集合对象
* @return JSONArray
* @since 3.0.8
public static JSONArray parseArray(Object arrayOrCollection) {
return new JSONArray(arrayOrCollection);
/**
* JSON字符串转JSONArray
* @param arrayOrCollection 数组或集合对象
* @return JSONArray
* @since 3.0.8
public static JSONArray parseArray(Object arrayOrCollection) {
return new JSONArray(arrayOrCollection);
/**
* JSON字符串转JSONArray
* @param jsonStr JSON字符串
* @return JSONArray
public static JSONArray parseArray(String jsonStr) {
return new JSONArray(jsonStr);
/**
* 创建 JSONArray
* @return JSONArray
public static JSONArray createArray() {
return new JSONArray();
/**
* JSON字符串转JSONArray
* @param arrayOrCollection 数组或集合对象
* @param ignoreNullValue 是否忽略空值
* @return JSONArray
* @since 3.2.3
public static JSONArray parseArray(Object arrayOrCollection, boolean ignoreNullValue) {
return new JSONArray(arrayOrCollection, ignoreNullValue);
/**
* 创建 JSONArray
* @return JSONArray
public static JSONArray createArray() {
return new JSONArray();
/**
* JSON字符串转JSONArray
* @param jsonStr JSON字符串
* @return JSONArray
public static JSONArray parseArray(String jsonStr) {
return new JSONArray(jsonStr);
/**
* JSON字符串转JSONArray
* @param arrayOrCollection 数组或集合对象
* @param ignoreNullValue 是否忽略空值
* @return JSONArray
* @since 3.2.3
public static JSONArray parseArray(Object arrayOrCollection, boolean ignoreNullValue) {
return new JSONArray(arrayOrCollection, ignoreNullValue);
/**
* 获得JSONArray对象<br>
* 如果值为其它类型对象,尝试转换为{@link JSONArray}返回,否则抛出异常
* @param key KEY
* @return JSONArray对象,如果值为null或者非JSONArray类型,返回null
public JSONArray getJSONArray(K key) {
final Object object = this.getObj(key);
if(null == object) {
return null;
if(object instanceof JSONArray) {
return (JSONArray) object;
return new JSONArray(object);
/**
* 获得JSONArray对象<br>
* 如果值为其它类型对象,尝试转换为{@link JSONArray}返回,否则抛出异常
* @param key KEY
* @return JSONArray对象,如果值为null或者非JSONArray类型,返回null
public JSONArray getJSONArray(K key) {
final Object object = this.getObj(key);
if(null == object) {
return null;
if(object instanceof JSONArray) {
return (JSONArray) object;
return new JSONArray(object);
json = new JSONArray(obj);
} else {// 对象
json = new JSONObject(obj);
json = new JSONArray(obj);
} else {// 对象
json = new JSONObject(obj);
/**
* 将指定KEY列表的值组成新的JSONArray
* @param names KEY列表
* @return A JSONArray of values.
* @throws JSONException If any of the values are non-finite numbers.
public JSONArray toJSONArray(Collection<String> names) throws JSONException {
if (CollectionUtil.isEmpty(names)) {
return null;
final JSONArray ja = new JSONArray();
Object value;
for (String name : names) {
value = this.get(name);
if (null != value) {
ja.put(value);
return ja;
/**
* 将指定KEY列表的值组成新的JSONArray
* @param names KEY列表
* @return A JSONArray of values.
* @throws JSONException If any of the values are non-finite numbers.
public JSONArray toJSONArray(Collection<String> names) throws JSONException {
if (CollectionUtil.isEmpty(names)) {
return null;
final JSONArray ja = new JSONArray();
Object value;
for (String name : names) {
value = this.get(name);
if (null != value) {
ja.put(value);
return ja;
/**
* 积累值。类似于put,当key对应value已经存在时,与value组成新的JSONArray. <br>
* 如果只有一个值,此值就是value,如果多个值,则是添加到新的JSONArray中
* @param key 键
* @param value 被积累的值
* @return this.
* @throws JSONException 如果给定键为<code>null</code>或者键对应的值存在且为非JSONArray
public JSONObject accumulate(String key, Object value) throws JSONException {
InternalJSONUtil.testValidity(value);
Object object = this.getObj(key);
if (object == null) {
this.put(key, value instanceof JSONArray ? new JSONArray().put(value) : value);
} else if (object instanceof JSONArray) {
((JSONArray) object).put(value);
} else {
this.put(key, new JSONArray().put(object).put(value));
return this;
/**
* 积累值。类似于put,当key对应value已经存在时,与value组成新的JSONArray. <br>
* 如果只有一个值,此值就是value,如果多个值,则是添加到新的JSONArray中
* @param key 键
* @param value 被积累的值
* @return this.
* @throws JSONException 如果给定键为<code>null</code>或者键对应的值存在且为非JSONArray
public JSONObject accumulate(String key, Object value) throws JSONException {
InternalJSONUtil.testValidity(value);
Object object = this.getObj(key);
if (object == null) {
this.put(key, value instanceof JSONArray ? new JSONArray().put(value) : value);
} else if (object instanceof JSONArray) {
((JSONArray) object).put(value);
} else {
this.put(key, new JSONArray().put(object).put(value));
return this;
/**
* 追加值,如果key无对应值,就添加一个JSONArray,其元素只有value,如果值已经是一个JSONArray,则添加到值JSONArray中。
* @param key 键
* @param value 值
* @return this.
* @throws JSONException 如果给定键为<code>null</code>或者键对应的值存在且为非JSONArray
public JSONObject append(String key, Object value) throws JSONException {
InternalJSONUtil.testValidity(value);
Object object = this.getObj(key);
if (object == null) {
this.put(key, new JSONArray().put(value));
} else if (object instanceof JSONArray) {
this.put(key, ((JSONArray) object).put(value));
} else {
throw new JSONException("JSONObject [" + key + "] is not a JSONArray.");
return this;
/**
* 追加值,如果key无对应值,就添加一个JSONArray,其元素只有value,如果值已经是一个JSONArray,则添加到值JSONArray中。
* @param key 键
* @param value 值
* @return this.
* @throws JSONException 如果给定键为<code>null</code>或者键对应的值存在且为非JSONArray
public JSONObject append(String key, Object value) throws JSONException {
InternalJSONUtil.testValidity(value);
Object object = this.getObj(key);
if (object == null) {
this.put(key, new JSONArray().put(value));
} else if (object instanceof JSONArray) {
this.put(key, ((JSONArray) object).put(value));
} else {
throw new JSONException("JSONObject [" + key + "] is not a JSONArray.");
return this;
JSONArray jsonArray = new JSONArray();
if (this.nextClean() != '[') {
throw this.syntaxError("A JSONArray text must start with '['");