public class JSONArray extends java.lang.Object implements JSONExpandable<java.lang.Object>, Copyable
构造器和说明 |
---|
JSONArray()
Create an empty instance
|
JSONArray(java.util.Collection collection) |
JSONArray(java.util.List list)
Create an instance from a List.
|
JSONArray(java.lang.Object array) |
JSONArray(java.lang.String json)
Create an instance from a String of JSON
|
限定符和类型 | 方法和说明 |
---|---|
JSONArray |
add(boolean value)
Add a boolean to the JSON array.
|
JSONArray |
add(java.lang.Boolean value)
Add a Boolean to the JSON array.
|
JSONArray |
add(byte[] value)
Add a binary value to the JSON array.
|
JSONArray |
add(java.lang.CharSequence value)
Add a CharSequence to the JSON array.
|
JSONArray |
add(java.util.Date value) |
JSONArray |
add(double value)
Add a double to the JSON array.
|
JSONArray |
add(java.lang.Double value)
Add a Double to the JSON array.
|
JSONArray |
add(java.lang.Enum value)
Add an enum to the JSON array.
|
JSONArray |
add(float value)
Add a float to the JSON array.
|
JSONArray |
add(java.lang.Float value)
Add a Float to the JSON array.
|
JSONArray |
add(java.lang.Integer value)
Add an Integer to the JSON array.
|
JSONArray |
add(JSONArray value)
Add another JSON array to the JSON array.
|
JSONArray |
add(JSONObject value)
Add a JSON object to the JSON array.
|
JSONArray |
add(long value)
Add a long to the JSON array.
|
JSONArray |
add(java.lang.Long value)
Add a Long to the JSON array.
|
JSONArray |
add(java.lang.Object value)
Add an Object to the JSON array.
|
JSONArray |
add(java.lang.String value)
Add a String to the JSON array.
|
JSONArray |
addAll(JSONArray array)
Appends all of the elements in the specified array to the end of this JSON array.
|
JSONArray |
addNull()
Add a null value to the JSON array.
|
JSONArray |
cjkEncode() |
JSONArray |
clear()
Remove all entries from the JSON array
|
boolean |
contains(java.lang.Object value)
Does the JSON array contain the specified value?
|
JSONArray |
copy()
Make a copy of the JSON array
|
static JSONArray |
create() |
static JSONArray |
create(java.util.Collection collection) |
static JSONArray |
create(java.util.Map<java.lang.String,java.lang.Object> map) |
java.lang.String |
encode()
Encode the JSON array to a string
|
java.lang.String |
encodePrettily()
Encode the JSON array prettily as a string
|
boolean |
equals(java.lang.Object o) |
java.lang.Object |
get(int index) |
byte[] |
getBinary(int pos)
Get the byte[] at position
pos in the array. |
boolean |
getBoolean(int index) |
double |
getDouble(int index) |
float |
getFloat(int index) |
java.util.Date |
getInstant(int pos)
获取时间
|
int |
getInt(int index) |
JSONArray |
getJSONArray(int pos)
Get the JsonArray at position
pos in the array. |
JSONObject |
getJSONObject(int pos)
Get the JsonObject at position
pos in the array. |
java.util.List |
getList()
Get the unerlying List
|
long |
getLong(int index) |
java.lang.Double |
getNumberOfDouble(int pos)
Get the Double at position
pos in the array, |
java.lang.Float |
getNumberOfFloat(int pos)
Get the Float at position
pos in the array, |
java.lang.Integer |
getNumberOfInteger(int pos)
Get the Integer at position
pos in the array, |
java.lang.Long |
getNumberOfLong(int pos)
Get the Long at position
pos in the array, |
java.lang.Boolean |
getObjectBoolean(int pos)
Get the Boolean at position
pos in the array, |
java.lang.String |
getString(int pos)
Get the String at position
pos in the array, |
java.lang.Object |
getValue(int pos)
Get the Object value at position
pos in the array. |
int |
hashCode() |
boolean |
hasNull(int pos)
Is there a null value at position pos?
|
boolean |
isEmpty()
Are there zero items in this JSON array?
|
java.util.Iterator<java.lang.Object> |
iterator()
Get an Iterator over the values in the JSON array
|
int |
length() |
java.lang.Object |
opt(int index) |
boolean |
optBoolean(int index) |
boolean |
optBoolean(int index,
boolean defaultValue) |
double |
optDouble(int index) |
double |
optDouble(int index,
double defaultValue) |
int |
optInt(int index) |
int |
optInt(int index,
int defaultValue) |
JSONArray |
optJSONArray(int index) |
JSONObject |
optJSONObject(int index) |
long |
optLong(int index) |
long |
optLong(int index,
long defaultValue) |
java.lang.String |
optString(int index) |
java.lang.String |
optString(int index,
java.lang.String defaultValue) |
JSONArray |
put(boolean value) |
JSONArray |
put(java.util.Collection value) |
JSONArray |
put(double value) |
JSONArray |
put(int value) |
JSONArray |
put(int index,
boolean value) |
JSONArray |
put(int index,
java.util.Collection value) |
JSONArray |
put(int index,
double value) |
JSONArray |
put(int index,
int value) |
JSONArray |
put(int index,
long value) |
JSONArray |
put(int index,
java.util.Map<java.lang.String,java.lang.Object> value) |
JSONArray |
put(int index,
java.lang.Object value) |
JSONArray |
put(long value) |
JSONArray |
put(java.util.Map<java.lang.String,java.lang.Object> value) |
JSONArray |
put(java.lang.Object value) |
java.lang.Object |
remove(int pos)
Remove the value at the specified position in the JSON array.
|
boolean |
remove(java.lang.Object value)
Remove the specified value from the JSON array.
|
int |
size()
Get the number of values in this JSON array
|
java.util.List<java.lang.Object> |
toRecurseList()
递归输出JSON数组所有的元素以及子元素,如果子元素是集合,也把集合元素拆分后塞进输出结果
|
java.util.List<java.lang.Object> |
toSimpleRecurseList()
递归输出JSON数组的所有元素以及子元素,当子元素也是JSON数组的时候,会把JSON数组再次拆分然后把元素塞进输出结果
|
java.lang.String |
toString() |
java.util.List<?> |
toUnmodifiableList()
将JSON数组转化为一个不可修改的链表
|
public JSONArray(java.lang.String json)
json
- the string of JSONpublic JSONArray()
public JSONArray(java.util.List list)
list
- public JSONArray(java.util.Collection collection)
public JSONArray(java.lang.Object array) throws JSONException
JSONException
public static JSONArray create()
public static JSONArray create(java.util.Map<java.lang.String,java.lang.Object> map)
public static JSONArray create(java.util.Collection collection)
public java.lang.String getString(int pos)
pos
in the array,pos
- the position in the arrayjava.lang.ClassCastException
- if the value cannot be converted to Stringpublic java.lang.Integer getNumberOfInteger(int pos)
pos
in the array,pos
- the position in the arraypublic java.lang.Long getNumberOfLong(int pos)
pos
in the array,pos
- the position in the arraypublic java.lang.Double getNumberOfDouble(int pos)
pos
in the array,pos
- the position in the arraypublic java.lang.Float getNumberOfFloat(int pos)
pos
in the array,pos
- the position in the arraypublic java.lang.Boolean getObjectBoolean(int pos)
pos
in the array,pos
- the position in the arraypublic JSONObject getJSONObject(int pos)
pos
in the array.pos
- the position in the arrayjava.lang.ClassCastException
- if the value cannot be converted to JsonObjectpublic JSONArray getJSONArray(int pos)
pos
in the array.pos
- the position in the arrayjava.lang.ClassCastException
- if the value cannot be converted to JsonArraypublic byte[] getBinary(int pos)
pos
in the array.
JSON itself has no notion of a binary, so this method assumes there is a String value and it contains a Base64 encoded binary, which it decodes if found and returns.
This method should be used in conjunction with add(byte[])
pos
- the position in the arrayjava.lang.ClassCastException
- if the value cannot be converted to Stringjava.lang.IllegalArgumentException
- if the String value is not a legal Base64 encoded valuepublic java.util.Date getInstant(int pos)
pos
- 索引public java.lang.Object getValue(int pos)
pos
in the array.pos
- the position in the arraypublic boolean hasNull(int pos)
pos
- the position in the arraypublic JSONArray add(java.lang.Enum value)
JSON has no concept of encoding Enums, so the Enum will be converted to a String using the Enum.name()
method and the value added as a String.
value
- the valuepublic JSONArray add(java.lang.CharSequence value)
value
- the valuepublic JSONArray add(java.lang.String value)
value
- the valuepublic JSONArray add(java.lang.Integer value)
value
- the valuepublic JSONArray add(java.lang.Long value)
value
- the valuepublic JSONArray add(long value)
value
- the valuepublic JSONArray add(java.lang.Double value)
value
- the valuepublic JSONArray add(double value)
value
- the valuepublic JSONArray add(java.lang.Float value)
value
- the valuepublic JSONArray add(float value)
value
- the valuepublic JSONArray add(java.lang.Boolean value)
value
- the valuepublic JSONArray add(boolean value)
value
- the valuepublic JSONArray addNull()
public JSONArray add(JSONObject value)
value
- the valuepublic JSONArray add(JSONArray value)
value
- the valuepublic JSONArray add(byte[] value)
JSON has no notion of binary so the binary will be base64 encoded to a String, and the String added.
value
- the valuepublic JSONArray add(java.util.Date value)
public JSONArray add(java.lang.Object value)
value
- the valuepublic JSONArray addAll(JSONArray array)
array
- the arraypublic boolean contains(java.lang.Object value)
value
- the valuepublic boolean remove(java.lang.Object value)
value
- the value to removepublic java.lang.Object remove(int pos)
pos
- the position to remove the value atJSONObject
is built from
this Map and returned. It the value is a List, a JSONArray
is built form this List and returned.public int size()
public boolean isEmpty()
public java.util.List getList()
public JSONArray clear()
public java.util.Iterator<java.lang.Object> iterator()
iterator
在接口中 java.lang.Iterable<java.lang.Object>
public java.lang.String encode()
public java.lang.String encodePrettily()
public java.lang.String toString()
toString
在类中 java.lang.Object
public boolean equals(java.lang.Object o)
equals
在类中 java.lang.Object
public int hashCode()
hashCode
在类中 java.lang.Object
public int length()
public java.lang.Object get(int index) throws JSONException
JSONException
public boolean getBoolean(int index) throws JSONException
JSONException
public int getInt(int index) throws JSONException
JSONException
public long getLong(int index) throws JSONException
JSONException
public float getFloat(int index) throws JSONException
JSONException
public double getDouble(int index) throws JSONException
JSONException
public java.lang.Object opt(int index)
public java.lang.String optString(int index)
public java.lang.String optString(int index, java.lang.String defaultValue)
public int optInt(int index)
public int optInt(int index, int defaultValue)
public long optLong(int index)
public long optLong(int index, long defaultValue)
public double optDouble(int index)
public double optDouble(int index, double defaultValue)
public boolean optBoolean(int index)
public boolean optBoolean(int index, boolean defaultValue)
public JSONObject optJSONObject(int index)
public JSONArray optJSONArray(int index)
public JSONArray put(java.lang.Object value)
public JSONArray put(boolean value)
public JSONArray put(java.util.Collection value)
public JSONArray put(double value) throws JSONException
JSONException
public JSONArray put(int value)
public JSONArray put(long value)
public JSONArray put(java.util.Map<java.lang.String,java.lang.Object> value)
public JSONArray put(int index, java.lang.Object value) throws JSONException
JSONException
public JSONArray put(int index, boolean value) throws JSONException
JSONException
public JSONArray put(int index, java.util.Collection value) throws JSONException
JSONException
public JSONArray put(int index, double value) throws JSONException
JSONException
public JSONArray put(int index, int value) throws JSONException
JSONException
public JSONArray put(int index, long value) throws JSONException
JSONException
public JSONArray put(int index, java.util.Map<java.lang.String,java.lang.Object> value) throws JSONException
JSONException
public JSONArray cjkEncode()
public java.util.List<?> toUnmodifiableList()
public java.util.List<java.lang.Object> toSimpleRecurseList()
public java.util.List<java.lang.Object> toRecurseList()