public class JSONArray extends JSONGetter<Integer> implements JSON, Iterable<Object>
| 构造器和说明 |
|---|
JSONArray()
Construct an empty JSONArray.
|
JSONArray(JSONTokener x)
Construct a JSONArray from a JSONTokener.
|
JSONArray(Object arrayOrCollection)
Construct a JSONArray from an array or Collection
|
JSONArray(String source)
Construct a JSONArray from a source JSON text.
|
| 限定符和类型 | 方法和说明 |
|---|---|
Object |
get(int index)
Get the optional object value associated with an index.
|
Object |
getObj(Integer index,
Object defaultValue)
获取Object属性值
|
boolean |
isNull(int index)
Determine if the value is null.
|
Iterator<Object> |
iterator() |
String |
join(String separator)
Make a string from the contents of this JSONArray.
|
int |
length()
Get the number of elements in the JSONArray, included nulls.
|
JSONArray |
put(int index,
Object value)
加入或者替换JSONArray中指定Index的值,如果index大于JSONArray的长度,将在指定index设置值,之前的位置填充JSONNull.Null
|
JSONArray |
put(Object value)
Append an object value.
|
Object |
remove(int index)
Remove an index and close the hole.
|
boolean |
similar(Object other)
Determine if two JSONArrays are similar.
|
JSONObject |
toJSONObject(JSONArray names)
Produce a JSONObject by combining a JSONArray of names with the values of this JSONArray.
|
String |
toJSONString(int indentFactor)
Make a prettyprinted JSON text of this JSONArray.
|
String |
toString()
Make a JSON text of this JSONArray.
|
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. |
getJSONArray, getJSONObjectgetBigDecimal, getBigInteger, getBool, getByte, getChar, getDouble, getEnum, getFloat, getInt, getLong, getShort, getStrgetBigDecimal, getBigInteger, getBool, getByte, getChar, getDouble, getEnum, getFloat, getInt, getLong, getObj, getShort, getStrpublic JSONArray()
public JSONArray(JSONTokener x) throws JSONException
x - A JSONTokenerJSONException - If there is a syntax error.public JSONArray(String source) throws JSONException
source - A string that begins with [ (left bracket) and ends with ] (right bracket).JSONException - If there is a syntax error.public JSONArray(Object arrayOrCollection) throws JSONException
JSONException - If not an array.public boolean isNull(int index)
index - The index must be between 0 and length() - 1.public String join(String separator) throws JSONException
separator string is inserted between each element. Warning: This method assumes that the data structure is acyclical.separator - A string that will be inserted between the elements.JSONException - If the array contains an invalid number.public int length()
public Object get(int index)
index - The index must be between 0 and length() - 1.public Object getObj(Integer index, Object defaultValue)
OptBasicTypeGettergetObj 在接口中 OptBasicTypeGetter<Integer>getObj 在类中 OptNullBasicTypeFromObjectGetter<Integer>index - 属性名defaultValue - 默认值public JSONArray put(Object value)
value - An object value. The value should be a Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the JSONNull.NULL object.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 Object remove(int index)
index - The index of the element to be removed.public boolean similar(Object other)
other - The other JSONArraypublic JSONObject toJSONObject(JSONArray names) throws JSONException
names - A JSONArray containing a list of key strings. These will be paired with the values.JSONException - If any of the names are null.public String toString()
Warning: This method assumes that the data structure is acyclical.
public String toJSONString(int indentFactor) throws JSONException
toJSONString 在接口中 JSONindentFactor - The number of spaces to add to each level of indentation.[ (left bracket) and ending with ] (right
bracket).JSONExceptionpublic Writer write(Writer writer) throws JSONException
JSONwrite 在接口中 JSONwriter - WriterJSONExceptionpublic Writer write(Writer writer, int indentFactor, int indent) throws JSONException
JSONwrite 在接口中 JSONwriter - writerindentFactor - 每一级别的缩进量indent - 顶级别缩进量JSONExceptionCopyright © 2016. All rights reserved.