diff --git a/allclasses-frame.html b/allclasses-frame.html index bcf41c4..22a46bf 100644 --- a/allclasses-frame.html +++ b/allclasses-frame.html @@ -2,7 +2,7 @@
- +public class CDL +extends Object+
+ Each row of text represents a row in a table or a data record. Each row + ends with a NEWLINE character. Each row contains one or more values. + Values are separated by commas. A value can contain any character except + for comma, unless is is wrapped in single quotes or double quotes. +
+ The first row usually contains the names of the columns. +
+ A comma delimited list can be converted into a JSONArray of JSONObjects. + The names for the elements in the JSONObjects can be taken from the names + in the first row.
Modifier and Type | +Method and Description | +
---|---|
static JSONArray |
+rowToJSONArray(JSONTokener x)
+Produce a JSONArray of strings from a row of comma delimited values.
+ |
+
static JSONObject |
+rowToJSONObject(JSONArray names,
+ JSONTokener x)
+Produce a JSONObject from a row of comma delimited text, using a
+ parallel JSONArray of strings to provides the names of the elements.
+ |
+
static String |
+rowToString(JSONArray ja)
+Produce a comma delimited text row from a JSONArray.
+ |
+
static JSONArray |
+toJSONArray(JSONArray names,
+ JSONTokener x)
+Produce a JSONArray of JSONObjects from a comma delimited text string
+ using a supplied JSONArray as the source of element names.
+ |
+
static JSONArray |
+toJSONArray(JSONArray names,
+ String string)
+Produce a JSONArray of JSONObjects from a comma delimited text string
+ using a supplied JSONArray as the source of element names.
+ |
+
static JSONArray |
+toJSONArray(JSONTokener x)
+Produce a JSONArray of JSONObjects from a comma delimited text string,
+ using the first row as a source of names.
+ |
+
static JSONArray |
+toJSONArray(String string)
+Produce a JSONArray of JSONObjects from a comma delimited text string,
+ using the first row as a source of names.
+ |
+
static String |
+toString(JSONArray ja)
+Produce a comma delimited text from a JSONArray of JSONObjects.
+ |
+
static String |
+toString(JSONArray names,
+ JSONArray ja)
+Produce a comma delimited text from a JSONArray of JSONObjects using
+ a provided list of names.
+ |
+
public static JSONArray rowToJSONArray(JSONTokener x) + throws JSONException+
x
- A JSONTokener of the source text.JSONException
- if a called function failspublic static JSONObject rowToJSONObject(JSONArray names, + JSONTokener x) + throws JSONException+
names
- A JSONArray of names. This is commonly obtained from the
+ first row of a comma delimited text file using the rowToJSONArray
+ method.x
- A JSONTokener of the source text.JSONException
- if a called function failspublic static String rowToString(JSONArray ja)+
ja
- A JSONArray of strings.public static JSONArray toJSONArray(String string) + throws JSONException+
string
- The comma delimited text.JSONException
- if a called function failspublic static JSONArray toJSONArray(JSONTokener x) + throws JSONException+
x
- The JSONTokener containing the comma delimited text.JSONException
- if a called function failspublic static JSONArray toJSONArray(JSONArray names, + String string) + throws JSONException+
names
- A JSONArray of strings.string
- The comma delimited text.JSONException
- if a called function failspublic static JSONArray toJSONArray(JSONArray names, + JSONTokener x) + throws JSONException+
names
- A JSONArray of strings.x
- A JSONTokener of the source text.JSONException
- if a called function failspublic static String toString(JSONArray ja) + throws JSONException+
ja
- A JSONArray of JSONObjects.JSONException
- if a called function failspublic static String toString(JSONArray names, + JSONArray ja) + throws JSONException+
names
- A JSONArray of strings.ja
- A JSONArray of JSONObjects.JSONException
- if a called function failspublic class Cookie +extends Object+
Modifier and Type | +Method and Description | +
---|---|
static String |
+escape(String string)
+Produce a copy of a string in which the characters '+', '%', '=', ';'
+ and control characters are replaced with "%hh".
+ |
+
static JSONObject |
+toJSONObject(String string)
+Convert a cookie specification string into a JSONObject.
+ |
+
static String |
+toString(JSONObject jo)
+Convert a JSONObject into a cookie specification string.
+ |
+
static String |
+unescape(String string)
+Convert
+% hh sequences to single characters, and
+ convert plus to space. |
+
public static String escape(String string)+
string
- The source string.public static JSONObject toJSONObject(String string)+
Boolean.TRUE
will be used for these).
+ The name will be stored under the key "name", and the value will be
+ stored under the key "value". This method does not do checking or
+ validation of the parameters. It only converts the cookie string into
+ a JSONObject. All attribute names are converted to lower case keys in the
+ JSONObject (HttpOnly => httponly). If an attribute is specified more than
+ once, only the value found closer to the end of the cookie-string is kept.string
- The cookie specification string.JSONException
- If there is an error parsing the Cookie String.
+ Cookie strings must have at least one '=' character and the 'name'
+ portion of the cookie must not be blank.public static String toString(JSONObject jo) + throws JSONException+
jo
- A JSONObjectJSONException
- thrown if the cookie has no name.public class CookieList +extends Object+
Constructor and Description | +
---|
CookieList() |
+
Modifier and Type | +Method and Description | +
---|---|
static JSONObject |
+toJSONObject(String string)
+Convert a cookie list into a JSONObject.
+ |
+
static String |
+toString(JSONObject jo)
+Convert a JSONObject into a cookie list.
+ |
+
public static JSONObject toJSONObject(String string) + throws JSONException+
string
- A cookie list stringJSONException
- if a called function failspublic static String toString(JSONObject jo) + throws JSONException+
jo
- A JSONObjectJSONException
- if a called function failspublic class HTTP +extends Object+
Modifier and Type | +Field and Description | +
---|---|
static String |
+CRLF
+Carriage return/line feed.
+ |
+
Modifier and Type | +Method and Description | +
---|---|
static JSONObject |
+toJSONObject(String string)
+Convert an HTTP header string into a JSONObject.
+ |
+
static String |
+toString(JSONObject jo)
+Convert a JSONObject into an HTTP header.
+ |
+
public static final String CRLF+
public static JSONObject toJSONObject(String string) + throws JSONException+
{ + Method: "POST" (for example), + "Request-URI": "/" (for example), + "HTTP-Version": "HTTP/1.1" (for example) + }+ A response header will contain +
{ + "HTTP-Version": "HTTP/1.1" (for example), + "Status-Code": "200" (for example), + "Reason-Phrase": "OK" (for example) + }+ In addition, the other parameters in the header will be captured, using + the HTTP field names as JSON names, so that
+ Date: Sun, 26 May 2002 18:06:04 GMT
+ Cookie: Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s
+ Cache-Control: no-cache
+ become
+
+ Date: "Sun, 26 May 2002 18:06:04 GMT",
+ Cookie: "Q=q2=PPEAsg--; B=677gi6ouf29bn&b=2&f=s",
+ "Cache-Control": "no-cache",
+ ...
+ It does no further checking or conversion. It does not parse dates.
+ It does not do '%' transforms on URLs.string
- An HTTP header string.JSONException
- if a called function failspublic static String toString(JSONObject jo) + throws JSONException+
{ + Method: "POST" (for example), + "Request-URI": "/" (for example), + "HTTP-Version": "HTTP/1.1" (for example) + }+ A response header must contain +
{ + "HTTP-Version": "HTTP/1.1" (for example), + "Status-Code": "200" (for example), + "Reason-Phrase": "OK" (for example) + }+ Any other members of the JSONObject will be output as HTTP fields. + The result will end with two CRLF pairs.
jo
- A JSONObjectJSONException
- if the object does not contain enough
+ information.public class HTTPTokener +extends JSONTokener+
Constructor and Description | +
---|
HTTPTokener(String string)
+Construct an HTTPTokener from a string.
+ |
+
Modifier and Type | +Method and Description | +
---|---|
String |
+nextToken()
+Get the next token or string.
+ |
+
back, dehexchar, end, more, next, next, next, nextClean, nextString, nextTo, nextTo, nextValue, skipTo, syntaxError, syntaxError, toString
public HTTPTokener(String string)+
string
- A source string.public String nextToken() + throws JSONException+
JSONException
- if a syntax error occurspublic class JSONArray +extends Object +implements Iterable<Object>+
get
and opt
+ methods for accessing the values by index, and put
methods for
+ adding or replacing values. The values can be any of these types:
+ Boolean
, JSONArray
, JSONObject
,
+ Number
, String
, or the
+ JSONObject.NULL object
.
+
+ The constructor can convert a JSON text into a Java object. The
+ toString
method converts to JSON text.
+
+ A get
method returns a value if one can be found, and throws an
+ exception if one cannot be found. An opt
method returns a
+ default value instead of throwing an exception, and so is useful for
+ obtaining optional values.
+
+ The generic get()
and opt()
methods return an
+ object which you can cast or query for type. There are also typed
+ get
and opt
methods that do type checking and type
+ coercion for you.
+
+ The texts produced by the toString
methods strictly conform to
+ JSON syntax rules. The constructors are more forgiving in the texts they will
+ accept:
+
,
(comma) may appear just
+ before the closing bracket.null
value will be inserted when there is ,
+ (comma) elision.'
(single
+ quote).{ } [ ] / \ : , #
and if they do not look like numbers and
+ if they are not the reserved words true
, false
, or
+ null
.Constructor and Description | +
---|
JSONArray()
+Construct an empty JSONArray.
+ |
+
JSONArray(Collection<?> collection)
+Construct a JSONArray from a Collection.
+ |
+
JSONArray(int initialCapacity)
+Construct a JSONArray with the specified initial capacity.
+ |
+
JSONArray(Iterable<?> iter)
+Construct a JSONArray from an Iterable.
+ |
+
JSONArray(JSONArray array)
+Construct a JSONArray from another JSONArray.
+ |
+
JSONArray(JSONTokener x)
+Construct a JSONArray from a JSONTokener.
+ |
+
JSONArray(Object array)
+Construct a JSONArray from an array.
+ |
+
JSONArray(String source)
+Construct a JSONArray from a source JSON text.
+ |
+
Modifier and Type | +Method and Description | +
---|---|
Object |
+get(int index)
+Get the object value associated with an index.
+ |
+
BigDecimal |
+getBigDecimal(int index)
+Get the BigDecimal value associated with an index.
+ |
+
BigInteger |
+getBigInteger(int index)
+Get the BigInteger value associated with an index.
+ |
+
boolean |
+getBoolean(int index)
+Get the boolean value associated with an index.
+ |
+
double |
+getDouble(int index)
+Get the double value associated with an index.
+ |
+
<E extends Enum<E>> |
+getEnum(Class<E> clazz,
+ int index)
+Get the enum value associated with an index.
+ |
+
float |
+getFloat(int index)
+Get the float value associated with a key.
+ |
+
int |
+getInt(int index)
+Get the int value associated with an index.
+ |
+
JSONArray |
+getJSONArray(int index)
+Get the JSONArray associated with an index.
+ |
+
JSONObject |
+getJSONObject(int index)
+Get the JSONObject associated with an index.
+ |
+
long |
+getLong(int index)
+Get the long value associated with an index.
+ |
+
Number |
+getNumber(int index)
+Get the Number value associated with a key.
+ |
+
String |
+getString(int index)
+Get the string associated with an index.
+ |
+
boolean |
+isEmpty()
+Check if JSONArray is empty.
+ |
+
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.
+ |
+
Object |
+opt(int index)
+Get the optional object value associated with an index.
+ |
+
BigDecimal |
+optBigDecimal(int index,
+ BigDecimal defaultValue)
+Get the optional BigDecimal value associated with an index.
+ |
+
BigInteger |
+optBigInteger(int index,
+ BigInteger defaultValue)
+Get the optional BigInteger value associated with an index.
+ |
+
boolean |
+optBoolean(int index)
+Get the optional boolean value associated with an index.
+ |
+
boolean |
+optBoolean(int index,
+ boolean defaultValue)
+Get the optional boolean value associated with an index.
+ |
+
double |
+optDouble(int index)
+Get the optional double value associated with an index.
+ |
+
double |
+optDouble(int index,
+ double defaultValue)
+Get the optional double value associated with an index.
+ |
+
<E extends Enum<E>> |
+optEnum(Class<E> clazz,
+ int index)
+Get the enum value associated with a key.
+ |
+
<E extends Enum<E>> |
+optEnum(Class<E> clazz,
+ int index,
+ E defaultValue)
+Get the enum value associated with a key.
+ |
+
float |
+optFloat(int index)
+Get the optional float value associated with an index.
+ |
+
float |
+optFloat(int index,
+ float defaultValue)
+Get the optional float value associated with an index.
+ |
+
int |
+optInt(int index)
+Get the optional int value associated with an index.
+ |
+
int |
+optInt(int index,
+ int defaultValue)
+Get the optional int value associated with an index.
+ |
+
JSONArray |
+optJSONArray(int index)
+Get the optional JSONArray associated with an index.
+ |
+
JSONObject |
+optJSONObject(int index)
+Get the optional JSONObject associated with an index.
+ |
+
long |
+optLong(int index)
+Get the optional long value associated with an index.
+ |
+
long |
+optLong(int index,
+ long defaultValue)
+Get the optional long value associated with an index.
+ |
+
Number |
+optNumber(int index)
+Get an optional
+Number value associated with a key, or null
+ if there is no such key or if the value is not a number. |
+
Number |
+optNumber(int index,
+ Number defaultValue)
+Get an optional
+Number value associated with a key, or the default if there
+ is no such key or if the value is not a number. |
+
Object |
+optQuery(JSONPointer jsonPointer)
+Queries and returns a value from this object using
+jsonPointer , or
+ returns null if the query fails due to a missing key. |
+
Object |
+optQuery(String jsonPointer)
+Queries and returns a value from this object using
+jsonPointer , or
+ returns null if the query fails due to a missing key. |
+
String |
+optString(int index)
+Get the optional string value associated with an index.
+ |
+
String |
+optString(int index,
+ String defaultValue)
+Get the optional string associated with an index.
+ |
+
JSONArray |
+put(boolean value)
+Append a boolean value.
+ |
+
JSONArray |
+put(Collection<?> value)
+Put a value in the JSONArray, where the value will be a JSONArray which
+ is produced from a Collection.
+ |
+
JSONArray |
+put(double value)
+Append a double value.
+ |
+
JSONArray |
+put(float value)
+Append a float value.
+ |
+
JSONArray |
+put(int value)
+Append an int value.
+ |
+
JSONArray |
+put(int index,
+ boolean value)
+Put or replace a boolean value in the JSONArray.
+ |
+
JSONArray |
+put(int index,
+ Collection<?> value)
+Put a value in the JSONArray, where the value will be a JSONArray which
+ is produced from a Collection.
+ |
+
JSONArray |
+put(int index,
+ double value)
+Put or replace a double value.
+ |
+
JSONArray |
+put(int index,
+ float value)
+Put or replace a float value.
+ |
+
JSONArray |
+put(int index,
+ int value)
+Put or replace an int value.
+ |
+
JSONArray |
+put(int index,
+ long value)
+Put or replace a long value.
+ |
+
JSONArray |
+put(int index,
+ Map<?,?> value)
+Put a value in the JSONArray, where the value will be a JSONObject that
+ is produced from a Map.
+ |
+
JSONArray |
+put(int index,
+ Object value)
+Put or replace an object value in the JSONArray.
+ |
+
JSONArray |
+put(long value)
+Append an long value.
+ |
+
JSONArray |
+put(Map<?,?> value)
+Put a value in the JSONArray, where the value will be a JSONObject which
+ is produced from a Map.
+ |
+
JSONArray |
+put(Object value)
+Append an object value.
+ |
+
JSONArray |
+putAll(Collection<?> collection)
+Put a collection's elements in to the JSONArray.
+ |
+
JSONArray |
+putAll(Iterable<?> iter)
+Put an Iterable's elements in to the JSONArray.
+ |
+
JSONArray |
+putAll(JSONArray array)
+Put a JSONArray's elements in to the JSONArray.
+ |
+
JSONArray |
+putAll(Object array)
+Put an array's elements in to the JSONArray.
+ |
+
Object |
+query(JSONPointer jsonPointer)
+Uses a user initialized JSONPointer and tries to
+ match it to an item within this JSONArray.
+ |
+
Object |
+query(String jsonPointer)
+Creates a JSONPointer using an initialization string and tries to
+ match it to an item within this JSONArray.
+ |
+
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.
+ |
+
List<Object> |
+toList()
+Returns a java.util.List containing all of the elements in this array.
+ |
+
String |
+toString()
+Make a JSON text of this JSONArray.
+ |
+
String |
+toString(int indentFactor)
+Make a pretty-printed JSON text of this JSONArray.
+ |
+
Writer |
+write(Writer writer)
+Write the contents of the JSONArray as JSON text to a writer.
+ |
+
Writer |
+write(Writer writer,
+ int indentFactor,
+ int indent)
+Write the contents of the JSONArray as JSON text to a writer.
+ |
+
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
public 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(Collection<?> collection)+
collection
- A Collection.public JSONArray(Iterable<?> iter)+
iter
- A Iterable collection.public JSONArray(JSONArray array)+
array
- A array.public JSONArray(Object array) + throws JSONException+
array
- Array. If the parameter passed is null, or not an array, an
+ exception will be thrown.JSONException
- If not an array or if an array value is non-finite number.NullPointerException
- Thrown if the array parameter is null.public JSONArray(int initialCapacity) + throws JSONException+
initialCapacity
- the initial capacity of the JSONArray.JSONException
- If the initial capacity is negative.public Object get(int index) + throws JSONException+
index
- The index must be between 0 and length() - 1.JSONException
- If there is no value for the index.public boolean getBoolean(int index) + throws JSONException+
index
- The index must be between 0 and length() - 1.JSONException
- If there is no value for the index or if the value is not
+ convertible to boolean.public double getDouble(int index) + throws JSONException+
index
- The index must be between 0 and length() - 1.JSONException
- If the key is not found or if the value cannot be converted
+ to a number.public float getFloat(int index) + throws JSONException+
index
- The index must be between 0 and length() - 1.JSONException
- if the key is not found or if the value is not a Number
+ object and cannot be converted to a number.public Number getNumber(int index) + throws JSONException+
index
- The index must be between 0 and length() - 1.JSONException
- if the key is not found or if the value is not a Number
+ object and cannot be converted to a number.public <E extends Enum<E>> E getEnum(Class<E> clazz, + int index) + throws JSONException+
E
- Enum Typeclazz
- The type of enum to retrieve.index
- The index must be between 0 and length() - 1.JSONException
- if the key is not found or if the value cannot be converted
+ to an enum.public BigDecimal getBigDecimal(int index) + throws JSONException+
BigDecimal.BigDecimal(double)
constructor
+ will be used. See notes on the constructor for conversion issues that
+ may arise.index
- The index must be between 0 and length() - 1.JSONException
- If the key is not found or if the value cannot be converted
+ to a BigDecimal.public BigInteger getBigInteger(int index) + throws JSONException+
index
- The index must be between 0 and length() - 1.JSONException
- If the key is not found or if the value cannot be converted
+ to a BigInteger.public int getInt(int index) + throws JSONException+
index
- The index must be between 0 and length() - 1.JSONException
- If the key is not found or if the value is not a number.public JSONArray getJSONArray(int index) + throws JSONException+
index
- The index must be between 0 and length() - 1.JSONException
- If there is no value for the index. or if the value is not a
+ JSONArraypublic JSONObject getJSONObject(int index) + throws JSONException+
index
- subscriptJSONException
- If there is no value for the index or if the value is not a
+ JSONObjectpublic long getLong(int index) + throws JSONException+
index
- The index must be between 0 and length() - 1.JSONException
- If the key is not found or if the value cannot be converted
+ to a number.public String getString(int index) + throws JSONException+
index
- The index must be between 0 and length() - 1.JSONException
- If there is no string value for the index.public boolean isNull(int index)+
null
.index
- The index must be between 0 and length() - 1.null
, or if there is no value.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 opt(int index)+
index
- The index must be between 0 and length() - 1. If not, null is returned.public boolean optBoolean(int index)+
index
- The index must be between 0 and length() - 1.public boolean optBoolean(int index, + boolean defaultValue)+
index
- The index must be between 0 and length() - 1.defaultValue
- A boolean default.public double optDouble(int index)+
index
- The index must be between 0 and length() - 1.public double optDouble(int index, + double defaultValue)+
index
- subscriptdefaultValue
- The default value.public float optFloat(int index)+
index
- The index must be between 0 and length() - 1.public float optFloat(int index, + float defaultValue)+
index
- subscriptdefaultValue
- The default value.public int optInt(int index)+
index
- The index must be between 0 and length() - 1.public int optInt(int index, + int defaultValue)+
index
- The index must be between 0 and length() - 1.defaultValue
- The default value.public <E extends Enum<E>> E optEnum(Class<E> clazz, + int index)+
E
- Enum Typeclazz
- The type of enum to retrieve.index
- The index must be between 0 and length() - 1.public <E extends Enum<E>> E optEnum(Class<E> clazz, + int index, + E defaultValue)+
E
- Enum Typeclazz
- The type of enum to retrieve.index
- The index must be between 0 and length() - 1.defaultValue
- The default in case the value is not foundpublic BigInteger optBigInteger(int index, + BigInteger defaultValue)+
index
- The index must be between 0 and length() - 1.defaultValue
- The default value.public BigDecimal optBigDecimal(int index, + BigDecimal defaultValue)+
BigDecimal.BigDecimal(double)
+ constructor will be used. See notes on the constructor for conversion
+ issues that may arise.index
- The index must be between 0 and length() - 1.defaultValue
- The default value.public JSONArray optJSONArray(int index)+
index
- subscriptpublic JSONObject optJSONObject(int index)+
index
- The index must be between 0 and length() - 1.public long optLong(int index)+
index
- The index must be between 0 and length() - 1.public long optLong(int index, + long defaultValue)+
index
- The index must be between 0 and length() - 1.defaultValue
- The default value.public Number optNumber(int index)+
Number
value associated with a key, or null
+ if there is no such key or if the value is not a number. If the value is a string,
+ an attempt will be made to evaluate it as a number (BigDecimal
). This method
+ would be used in cases where type coercion of the number value is unwanted.index
- The index must be between 0 and length() - 1.public Number optNumber(int index, + Number defaultValue)+
Number
value associated with a key, or the default if there
+ is no such key or if the value is not a number. If the value is a string,
+ an attempt will be made to evaluate it as a number (BigDecimal
). This method
+ would be used in cases where type coercion of the number value is unwanted.index
- The index must be between 0 and length() - 1.defaultValue
- The default.public String optString(int index)+
index
- The index must be between 0 and length() - 1.public String optString(int index, + String defaultValue)+
index
- The index must be between 0 and length() - 1.defaultValue
- The default value.public JSONArray put(boolean value)+
value
- A boolean value.public JSONArray put(Collection<?> value)+
value
- A Collection value.JSONException
- If the value is non-finite number.public JSONArray put(double value) + throws JSONException+
value
- A double value.JSONException
- if the value is not finite.public JSONArray put(float value) + throws JSONException+
value
- A float value.JSONException
- if the value is not finite.public JSONArray put(int value)+
value
- An int value.public JSONArray put(long value)+
value
- A long value.public JSONArray put(Map<?,?> value)+
value
- A Map value.JSONException
- If a value in the map is non-finite number.NullPointerException
- If a key in the map is null
public JSONArray put(Object value)+
value
- An object value. The value should be a Boolean, Double,
+ Integer, JSONArray, JSONObject, Long, or String, or the
+ JSONObject.NULL object.JSONException
- If the value is non-finite number.public JSONArray put(int index, + boolean value) + throws JSONException+
index
- The subscript.value
- A boolean value.JSONException
- If the index is negative.public JSONArray put(int index, + Collection<?> value) + throws JSONException+
index
- The subscript.value
- A Collection value.JSONException
- If the index is negative or if the value is non-finite.public JSONArray put(int index, + double value) + throws JSONException+
index
- The subscript.value
- A double value.JSONException
- If the index is negative or if the value is non-finite.public JSONArray put(int index, + float value) + throws JSONException+
index
- The subscript.value
- A float value.JSONException
- If the index is negative or if the value is non-finite.public JSONArray put(int index, + int value) + throws JSONException+
index
- The subscript.value
- An int value.JSONException
- If the index is negative.public JSONArray put(int index, + long value) + throws JSONException+
index
- The subscript.value
- A long value.JSONException
- If the index is negative.public JSONArray put(int index, + Map<?,?> value) + throws JSONException+
index
- The subscript.value
- The Map value.JSONException
- If the index is negative or if the the value is an invalid
+ number.NullPointerException
- If a key in the map is null
public JSONArray put(int index, + Object value) + throws JSONException+
index
- The subscript.value
- The value to put into the array. The value should be a
+ Boolean, Double, Integer, JSONArray, JSONObject, Long, or
+ String, or the JSONObject.NULL object.JSONException
- If the index is negative or if the the value is an invalid
+ number.public JSONArray putAll(Collection<?> collection)+
collection
- A Collection.public JSONArray putAll(Iterable<?> iter)+
iter
- An Iterable.public JSONArray putAll(JSONArray array)+
array
- A JSONArray.public JSONArray putAll(Object array) + throws JSONException+
array
- Array. If the parameter passed is null, or not an array or Iterable, an
+ exception will be thrown.JSONException
- If not an array, JSONArray, Iterable or if an value is non-finite number.NullPointerException
- Thrown if the array parameter is null.public Object query(String jsonPointer)+
+ [ + {"b":"c"} + ] ++ and this JSONPointer string: +
+ "/0/b" ++ Then this method will return the String "c" + A JSONPointerException may be thrown from code called by this method.
jsonPointer
- string that can be used to create a JSONPointerpublic Object query(JSONPointer jsonPointer)+
+ [ + {"b":"c"} + ] ++ and this JSONPointer: +
+ "/0/b" ++ Then this method will return the String "c" + A JSONPointerException may be thrown from code called by this method.
jsonPointer
- string that can be used to create a JSONPointerpublic Object optQuery(String jsonPointer)+
jsonPointer
, or
+ returns null if the query fails due to a missing key.jsonPointer
- the string representation of the JSON pointernull
IllegalArgumentException
- if jsonPointer
has invalid syntaxpublic Object optQuery(JSONPointer jsonPointer)+
jsonPointer
, or
+ returns null if the query fails due to a missing key.jsonPointer
- The JSON pointernull
IllegalArgumentException
- if jsonPointer
has invalid syntaxpublic 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 toString(int indentFactor) + throws JSONException+
If
indentFactor > 0
and the JSONArray
has only
+ one element, then the array will be output on a single line:
+ [1]
+
+ If an array has 2 or more elements, then it will be output across + multiple lines:
+ [
+ 1,
+ "value 2",
+ 3
+ ]
+
+ + Warning: This method assumes that the data structure is acyclical. +
indentFactor
- The number of spaces to add to each level of indentation.[
(left
+ bracket) and ending with ]
+ (right bracket).JSONException
- if a called function failspublic Writer write(Writer writer) + throws JSONException+
+ Warning: This method assumes that the data structure is acyclical. +
writer
- the writer objectJSONException
- if a called function failspublic Writer write(Writer writer, + int indentFactor, + int indent) + throws JSONException+
If
indentFactor > 0
and the JSONArray
has only
+ one element, then the array will be output on a single line:
+ [1]
+
+ If an array has 2 or more elements, then it will be output across + multiple lines:
+ [
+ 1,
+ "value 2",
+ 3
+ ]
+
+ + Warning: This method assumes that the data structure is acyclical. +
writer
- Writes the serialized JSONindentFactor
- The number of spaces to add to each level of indentation.indent
- The indentation of the top level.JSONException
- if a called function fails or unable to writepublic List<Object> toList()+
+ Warning: This method assumes that the data structure is acyclical.
public boolean isEmpty()+
public class JSONException +extends RuntimeException+
Constructor and Description | +
---|
JSONException(String message)
+Constructs a JSONException with an explanatory message.
+ |
+
JSONException(String message,
+ Throwable cause)
+Constructs a JSONException with an explanatory message and cause.
+ |
+
JSONException(Throwable cause)
+Constructs a new JSONException with the specified cause.
+ |
+
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
public JSONException(String message)+
message
- Detail about the reason for the exception.public JSONException(String message, + Throwable cause)+
message
- Detail about the reason for the exception.cause
- The cause.public JSONException(Throwable cause)+
cause
- The cause.public class JSONML +extends Object+
Modifier and Type | +Method and Description | +
---|---|
static JSONArray |
+toJSONArray(String string)
+Convert a well-formed (but not necessarily valid) XML string into a
+ JSONArray using the JsonML transform.
+ |
+
static JSONArray |
+toJSONArray(String string,
+ boolean keepStrings)
+Convert a well-formed (but not necessarily valid) XML string into a
+ JSONArray using the JsonML transform.
+ |
+
static JSONArray |
+toJSONArray(XMLTokener x)
+Convert a well-formed (but not necessarily valid) XML string into a
+ JSONArray using the JsonML transform.
+ |
+
static JSONArray |
+toJSONArray(XMLTokener x,
+ boolean keepStrings)
+Convert a well-formed (but not necessarily valid) XML string into a
+ JSONArray using the JsonML transform.
+ |
+
static JSONObject |
+toJSONObject(String string)
+Convert a well-formed (but not necessarily valid) XML string into a
+ JSONObject using the JsonML transform.
+ |
+
static JSONObject |
+toJSONObject(String string,
+ boolean keepStrings)
+Convert a well-formed (but not necessarily valid) XML string into a
+ JSONObject using the JsonML transform.
+ |
+
static JSONObject |
+toJSONObject(XMLTokener x)
+Convert a well-formed (but not necessarily valid) XML string into a
+ JSONObject using the JsonML transform.
+ |
+
static JSONObject |
+toJSONObject(XMLTokener x,
+ boolean keepStrings)
+Convert a well-formed (but not necessarily valid) XML string into a
+ JSONObject using the JsonML transform.
+ |
+
static String |
+toString(JSONArray ja)
+Reverse the JSONML transformation, making an XML text from a JSONArray.
+ |
+
static String |
+toString(JSONObject jo)
+Reverse the JSONML transformation, making an XML text from a JSONObject.
+ |
+
public static JSONArray toJSONArray(String string) + throws JSONException+
<[ [ ]]>
are ignored.string
- The source string.JSONException
- Thrown on error converting to a JSONArraypublic static JSONArray toJSONArray(String string, + boolean keepStrings) + throws JSONException+
<[ [ ]]>
are ignored.string
- The source string.keepStrings
- If true, then values will not be coerced into boolean
+ or numeric values and will instead be left as stringsJSONException
- Thrown on error converting to a JSONArraypublic static JSONArray toJSONArray(XMLTokener x, + boolean keepStrings) + throws JSONException+
<[ [ ]]>
are ignored.x
- An XMLTokener.keepStrings
- If true, then values will not be coerced into boolean
+ or numeric values and will instead be left as stringsJSONException
- Thrown on error converting to a JSONArraypublic static JSONArray toJSONArray(XMLTokener x) + throws JSONException+
<[ [ ]]>
are ignored.x
- An XMLTokener.JSONException
- Thrown on error converting to a JSONArraypublic static JSONObject toJSONObject(String string) + throws JSONException+
<[ [ ]]>
are ignored.string
- The XML source text.JSONException
- Thrown on error converting to a JSONObjectpublic static JSONObject toJSONObject(String string, + boolean keepStrings) + throws JSONException+
<[ [ ]]>
are ignored.string
- The XML source text.keepStrings
- If true, then values will not be coerced into boolean
+ or numeric values and will instead be left as stringsJSONException
- Thrown on error converting to a JSONObjectpublic static JSONObject toJSONObject(XMLTokener x) + throws JSONException+
<[ [ ]]>
are ignored.x
- An XMLTokener of the XML source text.JSONException
- Thrown on error converting to a JSONObjectpublic static JSONObject toJSONObject(XMLTokener x, + boolean keepStrings) + throws JSONException+
<[ [ ]]>
are ignored.x
- An XMLTokener of the XML source text.keepStrings
- If true, then values will not be coerced into boolean
+ or numeric values and will instead be left as stringsJSONException
- Thrown on error converting to a JSONObjectpublic static String toString(JSONArray ja) + throws JSONException+
ja
- A JSONArray.JSONException
- Thrown on error converting to a stringpublic static String toString(JSONObject jo) + throws JSONException+
jo
- A JSONObject.JSONException
- Thrown on error converting to a stringpublic class JSONObject +extends Object+
get
and opt
methods for accessing
+ the values by name, and put
methods for adding or replacing
+ values by name. The values can be any of these types: Boolean
,
+ JSONArray
, JSONObject
, Number
,
+ String
, or the JSONObject.NULL
object. A
+ JSONObject constructor can be used to convert an external form JSON text
+ into an internal form whose values can be retrieved with the
+ get
and opt
methods, or to convert values into a
+ JSON text using the put
and toString
methods. A
+ get
method returns a value if one can be found, and throws an
+ exception if one cannot be found. An opt
method returns a
+ default value instead of throwing an exception, and so is useful for
+ obtaining optional values.
+
+ The generic get()
and opt()
methods return an
+ object, which you can cast or query for type. There are also typed
+ get
and opt
methods that do type checking and type
+ coercion for you. The opt methods differ from the get methods in that they
+ do not throw. Instead, they return a specified value, such as null.
+
+ The put
methods add or replace values in an object. For
+ example,
+
+
+ myString = new JSONObject() + .put("JSON", "Hello, World!").toString(); ++ + produces the string
{"JSON": "Hello, World"}
.
+
+ The texts produced by the toString
methods strictly conform to
+ the JSON syntax rules. The constructors are more forgiving in the texts they
+ will accept:
+
,
(comma) may appear just
+ before the closing brace.'
(single
+ quote).{ } [ ] / \ : , #
and if they do not look like numbers and
+ if they are not the reserved words true
, false
,
+ or null
.Modifier and Type | +Field and Description | +
---|---|
static Object |
+NULL
+It is sometimes more convenient and less ambiguous to have a
+
+NULL object than to use Java's null value. |
+
Modifier | +Constructor and Description | +
---|---|
|
+JSONObject()
+Construct an empty JSONObject.
+ |
+
protected |
+JSONObject(int initialCapacity)
+Constructor to specify an initial capacity of the internal map.
+ |
+
|
+JSONObject(JSONObject jo,
+ String... names)
+Construct a JSONObject from a subset of another JSONObject.
+ |
+
|
+JSONObject(JSONTokener x)
+Construct a JSONObject from a JSONTokener.
+ |
+
|
+JSONObject(Map<?,?> m)
+Construct a JSONObject from a Map.
+ |
+
|
+JSONObject(Object bean)
+Construct a JSONObject from an Object using bean getters.
+ |
+
|
+JSONObject(Object object,
+ String... names)
+Construct a JSONObject from an Object, using reflection to find the
+ public members.
+ |
+
|
+JSONObject(String source)
+Construct a JSONObject from a source JSON text string.
+ |
+
|
+JSONObject(String baseName,
+ Locale locale)
+Construct a JSONObject from a ResourceBundle.
+ |
+
Modifier and Type | +Method and Description | +
---|---|
JSONObject |
+accumulate(String key,
+ Object value)
+Accumulate values under a key.
+ |
+
JSONObject |
+append(String key,
+ Object value)
+Append values to the array under a key.
+ |
+
static String |
+doubleToString(double d)
+Produce a string from a double.
+ |
+
protected Set<Map.Entry<String,Object>> |
+entrySet()
+Get a set of entries of the JSONObject.
+ |
+
Object |
+get(String key)
+Get the value object associated with a key.
+ |
+
BigDecimal |
+getBigDecimal(String key)
+Get the BigDecimal value associated with a key.
+ |
+
BigInteger |
+getBigInteger(String key)
+Get the BigInteger value associated with a key.
+ |
+
boolean |
+getBoolean(String key)
+Get the boolean value associated with a key.
+ |
+
double |
+getDouble(String key)
+Get the double value associated with a key.
+ |
+
<E extends Enum<E>> |
+getEnum(Class<E> clazz,
+ String key)
+Get the enum value associated with a key.
+ |
+
float |
+getFloat(String key)
+Get the float value associated with a key.
+ |
+
int |
+getInt(String key)
+Get the int value associated with a key.
+ |
+
JSONArray |
+getJSONArray(String key)
+Get the JSONArray value associated with a key.
+ |
+
JSONObject |
+getJSONObject(String key)
+Get the JSONObject value associated with a key.
+ |
+
long |
+getLong(String key)
+Get the long value associated with a key.
+ |
+
static String[] |
+getNames(JSONObject jo)
+Get an array of field names from a JSONObject.
+ |
+
static String[] |
+getNames(Object object)
+Get an array of public field names from an Object.
+ |
+
Number |
+getNumber(String key)
+Get the Number value associated with a key.
+ |
+
String |
+getString(String key)
+Get the string associated with a key.
+ |
+
boolean |
+has(String key)
+Determine if the JSONObject contains a specific key.
+ |
+
JSONObject |
+increment(String key)
+Increment a property of a JSONObject.
+ |
+
protected static boolean |
+isDecimalNotation(String val)
+Tests if the value should be tried as a decimal.
+ |
+
boolean |
+isEmpty()
+Check if JSONObject is empty.
+ |
+
boolean |
+isNull(String key)
+Determine if the value associated with the key is
+null or if there is no
+ value. |
+
Iterator<String> |
+keys()
+Get an enumeration of the keys of the JSONObject.
+ |
+
Set<String> |
+keySet()
+Get a set of keys of the JSONObject.
+ |
+
int |
+length()
+Get the number of keys stored in the JSONObject.
+ |
+
JSONArray |
+names()
+Produce a JSONArray containing the names of the elements of this
+ JSONObject.
+ |
+
static String |
+numberToString(Number number)
+Produce a string from a Number.
+ |
+
Object |
+opt(String key)
+Get an optional value associated with a key.
+ |
+
BigDecimal |
+optBigDecimal(String key,
+ BigDecimal defaultValue)
+Get an optional BigDecimal associated with a key, or the defaultValue if
+ there is no such key or if its value is not a number.
+ |
+
BigInteger |
+optBigInteger(String key,
+ BigInteger defaultValue)
+Get an optional BigInteger associated with a key, or the defaultValue if
+ there is no such key or if its value is not a number.
+ |
+
boolean |
+optBoolean(String key)
+Get an optional boolean associated with a key.
+ |
+
boolean |
+optBoolean(String key,
+ boolean defaultValue)
+Get an optional boolean associated with a key.
+ |
+
double |
+optDouble(String key)
+Get an optional double associated with a key, or NaN if there is no such
+ key or if its value is not a number.
+ |
+
double |
+optDouble(String key,
+ double defaultValue)
+Get an optional double associated with a key, or the defaultValue if
+ there is no such key or if its value is not a number.
+ |
+
<E extends Enum<E>> |
+optEnum(Class<E> clazz,
+ String key)
+Get the enum value associated with a key.
+ |
+
<E extends Enum<E>> |
+optEnum(Class<E> clazz,
+ String key,
+ E defaultValue)
+Get the enum value associated with a key.
+ |
+
float |
+optFloat(String key)
+Get the optional double value associated with an index.
+ |
+
float |
+optFloat(String key,
+ float defaultValue)
+Get the optional double value associated with an index.
+ |
+
int |
+optInt(String key)
+Get an optional int value associated with a key, or zero if there is no
+ such key or if the value is not a number.
+ |
+
int |
+optInt(String key,
+ int defaultValue)
+Get an optional int value associated with a key, or the default if there
+ is no such key or if the value is not a number.
+ |
+
JSONArray |
+optJSONArray(String key)
+Get an optional JSONArray associated with a key.
+ |
+
JSONObject |
+optJSONObject(String key)
+Get an optional JSONObject associated with a key.
+ |
+
long |
+optLong(String key)
+Get an optional long value associated with a key, or zero if there is no
+ such key or if the value is not a number.
+ |
+
long |
+optLong(String key,
+ long defaultValue)
+Get an optional long value associated with a key, or the default if there
+ is no such key or if the value is not a number.
+ |
+
Number |
+optNumber(String key)
+Get an optional
+Number value associated with a key, or null
+ if there is no such key or if the value is not a number. |
+
Number |
+optNumber(String key,
+ Number defaultValue)
+Get an optional
+Number value associated with a key, or the default if there
+ is no such key or if the value is not a number. |
+
Object |
+optQuery(JSONPointer jsonPointer)
+Queries and returns a value from this object using
+jsonPointer , or
+ returns null if the query fails due to a missing key. |
+
Object |
+optQuery(String jsonPointer)
+Queries and returns a value from this object using
+jsonPointer , or
+ returns null if the query fails due to a missing key. |
+
String |
+optString(String key)
+Get an optional string associated with a key.
+ |
+
String |
+optString(String key,
+ String defaultValue)
+Get an optional string associated with a key.
+ |
+
JSONObject |
+put(String key,
+ boolean value)
+Put a key/boolean pair in the JSONObject.
+ |
+
JSONObject |
+put(String key,
+ Collection<?> value)
+Put a key/value pair in the JSONObject, where the value will be a
+ JSONArray which is produced from a Collection.
+ |
+
JSONObject |
+put(String key,
+ double value)
+Put a key/double pair in the JSONObject.
+ |
+
JSONObject |
+put(String key,
+ float value)
+Put a key/float pair in the JSONObject.
+ |
+
JSONObject |
+put(String key,
+ int value)
+Put a key/int pair in the JSONObject.
+ |
+
JSONObject |
+put(String key,
+ long value)
+Put a key/long pair in the JSONObject.
+ |
+
JSONObject |
+put(String key,
+ Map<?,?> value)
+Put a key/value pair in the JSONObject, where the value will be a
+ JSONObject which is produced from a Map.
+ |
+
JSONObject |
+put(String key,
+ Object value)
+Put a key/value pair in the JSONObject.
+ |
+
JSONObject |
+putOnce(String key,
+ Object value)
+Put a key/value pair in the JSONObject, but only if the key and the value
+ are both non-null, and only if there is not already a member with that
+ name.
+ |
+
JSONObject |
+putOpt(String key,
+ Object value)
+Put a key/value pair in the JSONObject, but only if the key and the value
+ are both non-null.
+ |
+
Object |
+query(JSONPointer jsonPointer)
+Uses a user initialized JSONPointer and tries to
+ match it to an item within this JSONObject.
+ |
+
Object |
+query(String jsonPointer)
+Creates a JSONPointer using an initialization string and tries to
+ match it to an item within this JSONObject.
+ |
+
static String |
+quote(String string)
+Produce a string in double quotes with backslash sequences in all the
+ right places.
+ |
+
static Writer |
+quote(String string,
+ Writer w) |
+
Object |
+remove(String key)
+Remove a name and its value, if present.
+ |
+
boolean |
+similar(Object other)
+Determine if two JSONObjects are similar.
+ |
+
protected static Number |
+stringToNumber(String val)
+Converts a string to a number using the narrowest possible type.
+ |
+
static Object |
+stringToValue(String string)
+Try to convert a string into a number, boolean, or null.
+ |
+
static void |
+testValidity(Object o)
+Throw an exception if the object is a NaN or infinite number.
+ |
+
JSONArray |
+toJSONArray(JSONArray names)
+Produce a JSONArray containing the values of the members of this
+ JSONObject.
+ |
+
Map<String,Object> |
+toMap()
+Returns a java.util.Map containing all of the entries in this object.
+ |
+
String |
+toString()
+Make a JSON text of this JSONObject.
+ |
+
String |
+toString(int indentFactor)
+Make a pretty-printed JSON text of this JSONObject.
+ |
+
static String |
+valueToString(Object value)
+Make a JSON text of an Object value.
+ |
+
static Object |
+wrap(Object object)
+Wrap an object, if necessary.
+ |
+
Writer |
+write(Writer writer)
+Write the contents of the JSONObject as JSON text to a writer.
+ |
+
Writer |
+write(Writer writer,
+ int indentFactor,
+ int indent)
+Write the contents of the JSONObject as JSON text to a writer.
+ |
+
public static final Object NULL+
NULL
object than to use Java's null
value.
+ JSONObject.NULL.equals(null)
returns true
.
+ JSONObject.NULL.toString()
returns "null"
.public JSONObject()+
public JSONObject(JSONObject jo, + String... names)+
jo
- A JSONObject.names
- An array of strings.public JSONObject(JSONTokener x) + throws JSONException+
x
- A JSONTokener object containing the source string.JSONException
- If there is a syntax error in the source string or a
+ duplicated key.public JSONObject(Map<?,?> m)+
m
- A map object that can be used to initialize the contents of
+ the JSONObject.JSONException
- If a value in the map is non-finite number.NullPointerException
- If a key in the map is null
public JSONObject(Object bean)+
"get"
or
+ "is"
followed by an uppercase letter, the method is invoked,
+ and a key and the value returned from the getter method are put into the
+ new JSONObject.
+
+ The key is formed by removing the "get"
or "is"
+ prefix. If the second remaining character is not upper case, then the
+ first character is converted to lower case.
+
+ Methods that are static
, return void
,
+ have parameters, or are "bridge" methods, are ignored.
+
+ For example, if an object has a method named "getName"
, and
+ if the result of calling object.getName()
is
+ "Larry Fine"
, then the JSONObject will contain
+ "name": "Larry Fine"
.
+
+ The JSONPropertyName
annotation can be used on a bean getter to
+ override key name used in the JSONObject. For example, using the object
+ above with the getName
method, if we annotated it with:
+
+ @JSONPropertyName("FullName") + public String getName() { return this.name; } ++ The resulting JSON object would contain
"FullName": "Larry Fine"
+
+ Similarly, the JSONPropertyName
annotation can be used on non-
+ get
and is
methods. We can also override key
+ name used in the JSONObject as seen below even though the field would normally
+ be ignored:
+
+ @JSONPropertyName("FullName") + public String fullName() { return this.name; } ++ The resulting JSON object would contain
"FullName": "Larry Fine"
+
+ The JSONPropertyIgnore
annotation can be used to force the bean property
+ to not be serialized into JSON. If both JSONPropertyIgnore
and
+ JSONPropertyName
are defined on the same method, a depth comparison is
+ performed and the one closest to the concrete class being serialized is used.
+ If both annotations are at the same level, then the JSONPropertyIgnore
+ annotation takes precedent and the field is not serialized.
+ For example, the following declaration would prevent the getName
+ method from being serialized:
+
+ @JSONPropertyName("FullName") + @JSONPropertyIgnore + public String getName() { return this.name; } ++
bean
- An object that has getter methods that should be used to make
+ a JSONObject.public JSONObject(Object object, + String... names)+
object
- An object that has fields that should be used to make a
+ JSONObject.names
- An array of strings, the names of the fields to be obtained
+ from the object.public JSONObject(String source) + throws JSONException+
source
- A string beginning with {
(left
+ brace) and ending with }
+ (right brace).JSONException
- If there is a syntax error in the source string or a
+ duplicated key.public JSONObject(String baseName, + Locale locale) + throws JSONException+
baseName
- The ResourceBundle base name.locale
- The Locale to load the ResourceBundle for.JSONException
- If any JSONExceptions are detected.protected JSONObject(int initialCapacity)+
initialCapacity
- initial capacity of the internal map.public JSONObject accumulate(String key, + Object value) + throws JSONException+
key
- A key string.value
- An object to be accumulated under the key.JSONException
- If the value is non-finite number.NullPointerException
- If the key is null
.public JSONObject append(String key, + Object value) + throws JSONException+
key
- A key string.value
- An object to be accumulated under the key.JSONException
- If the value is non-finite number or if the current value associated with
+ the key is not a JSONArray.NullPointerException
- If the key is null
.public static String doubleToString(double d)+
d
- A double.public Object get(String key) + throws JSONException+
key
- A key string.JSONException
- if the key is not found.public <E extends Enum<E>> E getEnum(Class<E> clazz, + String key) + throws JSONException+
E
- Enum Typeclazz
- The type of enum to retrieve.key
- A key string.JSONException
- if the key is not found or if the value cannot be converted
+ to an enum.public boolean getBoolean(String key) + throws JSONException+
key
- A key string.JSONException
- if the value is not a Boolean or the String "true" or
+ "false".public BigInteger getBigInteger(String key) + throws JSONException+
key
- A key string.JSONException
- if the key is not found or if the value cannot
+ be converted to BigInteger.public BigDecimal getBigDecimal(String key) + throws JSONException+
BigDecimal.BigDecimal(double)
constructor will
+ be used. See notes on the constructor for conversion issues that may
+ arise.key
- A key string.JSONException
- if the key is not found or if the value
+ cannot be converted to BigDecimal.public double getDouble(String key) + throws JSONException+
key
- A key string.JSONException
- if the key is not found or if the value is not a Number
+ object and cannot be converted to a number.public float getFloat(String key) + throws JSONException+
key
- A key string.JSONException
- if the key is not found or if the value is not a Number
+ object and cannot be converted to a number.public Number getNumber(String key) + throws JSONException+
key
- A key string.JSONException
- if the key is not found or if the value is not a Number
+ object and cannot be converted to a number.public int getInt(String key) + throws JSONException+
key
- A key string.JSONException
- if the key is not found or if the value cannot be converted
+ to an integer.public JSONArray getJSONArray(String key) + throws JSONException+
key
- A key string.JSONException
- if the key is not found or if the value is not a JSONArray.public JSONObject getJSONObject(String key) + throws JSONException+
key
- A key string.JSONException
- if the key is not found or if the value is not a JSONObject.public long getLong(String key) + throws JSONException+
key
- A key string.JSONException
- if the key is not found or if the value cannot be converted
+ to a long.public static String[] getNames(JSONObject jo)+
jo
- JSON objectpublic static String[] getNames(Object object)+
object
- object to readpublic String getString(String key) + throws JSONException+
key
- A key string.JSONException
- if there is no string value for the key.public boolean has(String key)+
key
- A key string.public JSONObject increment(String key) + throws JSONException+
key
- A key string.JSONException
- If there is already a property with this name that is not an
+ Integer, Long, Double, or Float.public boolean isNull(String key)+
null
or if there is no
+ value.key
- A key string.public Iterator<String> keys()+
Set.iterator()
public Set<String> keySet()+
Map.keySet()
protected Set<Map.Entry<String,Object>> entrySet()+
Map.entrySet()
public int length()+
public boolean isEmpty()+
public JSONArray names()+
public static String numberToString(Number number) + throws JSONException+
number
- A NumberJSONException
- If n is a non-finite number.public Object opt(String key)+
key
- A key string.public <E extends Enum<E>> E optEnum(Class<E> clazz, + String key)+
E
- Enum Typeclazz
- The type of enum to retrieve.key
- A key string.public <E extends Enum<E>> E optEnum(Class<E> clazz, + String key, + E defaultValue)+
E
- Enum Typeclazz
- The type of enum to retrieve.key
- A key string.defaultValue
- The default in case the value is not foundclazz
public boolean optBoolean(String key)+
key
- A key string.public boolean optBoolean(String key, + boolean defaultValue)+
key
- A key string.defaultValue
- The default.public BigDecimal optBigDecimal(String key, + BigDecimal defaultValue)+
BigDecimal.BigDecimal(double)
+ constructor will be used. See notes on the constructor for conversion
+ issues that may arise.key
- A key string.defaultValue
- The default.public BigInteger optBigInteger(String key, + BigInteger defaultValue)+
key
- A key string.defaultValue
- The default.public double optDouble(String key)+
key
- A string which is the key.public double optDouble(String key, + double defaultValue)+
key
- A key string.defaultValue
- The default.public float optFloat(String key)+
key
- A key string.public float optFloat(String key, + float defaultValue)+
key
- A key string.defaultValue
- The default value.public int optInt(String key)+
key
- A key string.public int optInt(String key, + int defaultValue)+
key
- A key string.defaultValue
- The default.public JSONArray optJSONArray(String key)+
key
- A key string.public JSONObject optJSONObject(String key)+
key
- A key string.public long optLong(String key)+
key
- A key string.public long optLong(String key, + long defaultValue)+
key
- A key string.defaultValue
- The default.public Number optNumber(String key)+
Number
value associated with a key, or null
+ if there is no such key or if the value is not a number. If the value is a string,
+ an attempt will be made to evaluate it as a number (BigDecimal
). This method
+ would be used in cases where type coercion of the number value is unwanted.key
- A key string.public Number optNumber(String key, + Number defaultValue)+
Number
value associated with a key, or the default if there
+ is no such key or if the value is not a number. If the value is a string,
+ an attempt will be made to evaluate it as a number. This method
+ would be used in cases where type coercion of the number value is unwanted.key
- A key string.defaultValue
- The default.public String optString(String key)+
key
- A key string.public String optString(String key, + String defaultValue)+
key
- A key string.defaultValue
- The default.public JSONObject put(String key, + boolean value) + throws JSONException+
key
- A key string.value
- A boolean which is the value.JSONException
- If the value is non-finite number.NullPointerException
- If the key is null
.public JSONObject put(String key, + Collection<?> value) + throws JSONException+
key
- A key string.value
- A Collection value.JSONException
- If the value is non-finite number.NullPointerException
- If the key is null
.public JSONObject put(String key, + double value) + throws JSONException+
key
- A key string.value
- A double which is the value.JSONException
- If the value is non-finite number.NullPointerException
- If the key is null
.public JSONObject put(String key, + float value) + throws JSONException+
key
- A key string.value
- A float which is the value.JSONException
- If the value is non-finite number.NullPointerException
- If the key is null
.public JSONObject put(String key, + int value) + throws JSONException+
key
- A key string.value
- An int which is the value.JSONException
- If the value is non-finite number.NullPointerException
- If the key is null
.public JSONObject put(String key, + long value) + throws JSONException+
key
- A key string.value
- A long which is the value.JSONException
- If the value is non-finite number.NullPointerException
- If the key is null
.public JSONObject put(String key, + Map<?,?> value) + throws JSONException+
key
- A key string.value
- A Map value.JSONException
- If the value is non-finite number.NullPointerException
- If the key is null
.public JSONObject put(String key, + Object value) + throws JSONException+
null
, then the
+ key will be removed from the JSONObject if it is present.key
- A key string.value
- An object which is the value. It should be of one of these
+ types: Boolean, Double, Integer, JSONArray, JSONObject, Long,
+ String, or the JSONObject.NULL object.JSONException
- If the value is non-finite number.NullPointerException
- If the key is null
.public JSONObject putOnce(String key, + Object value) + throws JSONException+
key
- key to insert intovalue
- value to insertJSONException
- if the key is a duplicatepublic JSONObject putOpt(String key, + Object value) + throws JSONException+
key
- A key string.value
- An object which is the value. It should be of one of these
+ types: Boolean, Double, Integer, JSONArray, JSONObject, Long,
+ String, or the JSONObject.NULL object.JSONException
- If the value is a non-finite number.public Object query(String jsonPointer)+
+ { + "a":{"b":"c"} + } ++ and this JSONPointer string: +
+ "/a/b" ++ Then this method will return the String "c". + A JSONPointerException may be thrown from code called by this method.
jsonPointer
- string that can be used to create a JSONPointerpublic Object query(JSONPointer jsonPointer)+
+ { + "a":{"b":"c"} + } ++ and this JSONPointer: +
+ "/a/b" ++ Then this method will return the String "c". + A JSONPointerException may be thrown from code called by this method.
jsonPointer
- string that can be used to create a JSONPointerpublic Object optQuery(String jsonPointer)+
jsonPointer
, or
+ returns null if the query fails due to a missing key.jsonPointer
- the string representation of the JSON pointernull
IllegalArgumentException
- if jsonPointer
has invalid syntaxpublic Object optQuery(JSONPointer jsonPointer)+
jsonPointer
, or
+ returns null if the query fails due to a missing key.jsonPointer
- The JSON pointernull
IllegalArgumentException
- if jsonPointer
has invalid syntaxpublic static String quote(String string)+
string
- A Stringpublic static Writer quote(String string, + Writer w) + throws IOException+
IOException
public Object remove(String key)+
key
- The name to be removed.public boolean similar(Object other)+
other
- The other JSONObjectprotected static boolean isDecimalNotation(String val)+
val
- value to testprotected static Number stringToNumber(String val) + throws NumberFormatException+
val
- value to convertNumberFormatException
- thrown if the value is not a valid number. A public
+ caller should catch this and wrap it in a JSONException
if applicable.public static Object stringToValue(String string)+
string
- A String. can not be null.NullPointerException
- Thrown if the string is null.public static void testValidity(Object o) + throws JSONException+
o
- The object to test.JSONException
- If o is a non-finite number.public JSONArray toJSONArray(JSONArray names) + throws JSONException+
names
- A JSONArray containing a list of key strings. This determines
+ the sequence of the values in the result.JSONException
- If any of the values are non-finite numbers.public String toString()+
+ Warning: This method assumes that the data structure is acyclical. +
public String toString(int indentFactor) + throws JSONException+
If
indentFactor > 0
and the JSONObject
+ has only one key, then the object will be output on a single line:
+ {"key": 1}
+
+ If an object has 2 or more keys, then it will be output across + multiple lines:
{
+ "key1": 1,
+ "key2": "value 2",
+ "key3": 3
+ }
+ + Warning: This method assumes that the data structure is acyclical. +
indentFactor
- The number of spaces to add to each level of indentation.{
(left
+ brace) and ending with }
(right
+ brace).JSONException
- If the object contains an invalid number.public static String valueToString(Object value) + throws JSONException+
+ Warning: This method assumes that the data structure is acyclical.
value
- The value to be serialized.{
(left
+ brace) and ending with }
(right
+ brace).JSONException
- If the value is or contains an invalid number.public static Object wrap(Object object)+
null
, return the NULL
+ object. If it is an array or collection, wrap it in a JSONArray. If it is
+ a map, wrap it in a JSONObject. If it is a standard property (Double,
+ String, et al) then it is already wrapped. Otherwise, if it comes from
+ one of the java packages, turn it into a string. And if it doesn't, try
+ to wrap it in a JSONObject. If the wrapping fails, then null is returned.object
- The object to wrappublic Writer write(Writer writer) + throws JSONException+
+ Warning: This method assumes that the data structure is acyclical. +
writer
- the writer objectJSONException
- if a called function has an errorpublic Writer write(Writer writer, + int indentFactor, + int indent) + throws JSONException+
If
indentFactor > 0
and the JSONObject
+ has only one key, then the object will be output on a single line:
+ {"key": 1}
+
+ If an object has 2 or more keys, then it will be output across + multiple lines:
{
+ "key1": 1,
+ "key2": "value 2",
+ "key3": 3
+ }
+ + Warning: This method assumes that the data structure is acyclical. +
writer
- Writes the serialized JSONindentFactor
- The number of spaces to add to each level of indentation.indent
- The indentation of the top level.JSONException
- if a called function has an error or a write error
+ occurspublic Map<String,Object> toMap()+
+ Warning: This method assumes that the data structure is acyclical.
public static class JSONPointer.Builder +extends Object+
Modifier and Type | +Method and Description | +
---|---|
JSONPointer.Builder |
+append(int arrayIndex)
+Adds an integer to the reference token list.
+ |
+
JSONPointer.Builder |
+append(String token)
+Adds an arbitrary token to the list of reference tokens.
+ |
+
JSONPointer |
+build()
+Creates a
+JSONPointer instance using the tokens previously set using the
+ append(String) method calls. |
+
public JSONPointer build()+
JSONPointer
instance using the tokens previously set using the
+ append(String)
method calls.public JSONPointer.Builder append(String token)+
"a~b"
then you should simply pass the "a~b"
string as-is, there is no
+ need to escape it as "a~0b"
.token
- the new token to be appended to the listthis
NullPointerException
- if token
is nullpublic JSONPointer.Builder append(int arrayIndex)+
arrayIndex
- the array index to be added to the token listthis
public class JSONPointer +extends Object+
Modifier and Type | +Class and Description | +
---|---|
static class |
+JSONPointer.Builder
+This class allows the user to build a JSONPointer in steps, using
+ exactly one segment in each step.
+ |
+
Constructor and Description | +
---|
JSONPointer(List<String> refTokens) |
+
JSONPointer(String pointer)
+Pre-parses and initializes a new
+JSONPointer instance. |
+
Modifier and Type | +Method and Description | +
---|---|
static JSONPointer.Builder |
+builder()
+Static factory method for
+JSONPointer.Builder . |
+
Object |
+queryFrom(Object document)
+Evaluates this JSON Pointer on the given
+document . |
+
String |
+toString()
+Returns a string representing the JSONPointer path value using string
+ representation
+ |
+
String |
+toURIFragment()
+Returns a string representing the JSONPointer path value using URI
+ fragment identifier representation
+ |
+
public JSONPointer(String pointer)+
JSONPointer
instance. If you want to
+ evaluate the same JSON Pointer on different JSON documents then it is recommended
+ to keep the JSONPointer
instances due to performance considerations.pointer
- the JSON String or URI Fragment representation of the JSON pointer.IllegalArgumentException
- if pointer
is not a valid JSON pointerpublic static JSONPointer.Builder builder()+
JSONPointer.Builder
. Example usage:
+
+
+ JSONPointer pointer = JSONPointer.builder()
+ .append("obj")
+ .append("other~key").append("another/key")
+ .append("\"")
+ .append(0)
+ .build();
+
JSONPointer
instance by chained
+ JSONPointer.Builder.append(String)
calls.public Object queryFrom(Object document) + throws JSONPointerException+
document
. The document
+ is usually a JSONObject
or a JSONArray
instance, but the empty
+ JSON Pointer (""
) can be evaluated on any JSON values and in such case the
+ returned value will be document
itself.document
- the JSON document which should be the subject of querying.JSONPointerException
- if an error occurs during evaluationpublic String toString()+
public String toURIFragment()+
public class JSONPointerException +extends JSONException+
JSONPointer
if an error occurs
+ during evaluating a pointer.Constructor and Description | +
---|
JSONPointerException(String message) |
+
JSONPointerException(String message,
+ Throwable cause) |
+
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
@Documented + @Retention(value=RUNTIME) + @Target(value=METHOD) +public @interface JSONPropertyIgnore+
@Documented + @Retention(value=RUNTIME) + @Target(value=METHOD) +public @interface JSONPropertyName+
public interface JSONString
+JSONString
interface allows a toJSONString()
+ method so that a class can change the behavior of
+ JSONObject.toString()
, JSONArray.toString()
,
+ and JSONWriter.value(
Object)
. The
+ toJSONString
method will be used instead of the default behavior
+ of using the Object's toString()
method and quoting the result.Modifier and Type | +Method and Description | +
---|---|
String |
+toJSONString()
+The
+toJSONString method allows a class to produce its own JSON
+ serialization. |
+
public class JSONStringer +extends JSONWriter+
+ A JSONStringer instance provides a value
method for appending
+ values to the
+ text, and a key
+ method for adding keys before values in objects. There are array
+ and endArray
methods that make and bound array values, and
+ object
and endObject
methods which make and bound
+ object values. All of these methods return the JSONWriter instance,
+ permitting cascade style. For example,
+ myString = new JSONStringer() + .object() + .key("JSON") + .value("Hello, World!") + .endObject() + .toString();which produces the string
+ {"JSON":"Hello, World!"}+
+ The first method called must be array
or object
.
+ There are no methods for adding commas or colons. JSONStringer adds them for
+ you. Objects and arrays can be nested up to 20 levels deep.
+
+ This can sometimes be easier than using a JSONObject to build a string.
mode, writer
Constructor and Description | +
---|
JSONStringer()
+Make a fresh JSONStringer.
+ |
+
Modifier and Type | +Method and Description | +
---|---|
String |
+toString()
+Return the JSON text.
+ |
+
public JSONStringer()+
public String toString()+
null
if there was a
+ problem in the construction of the JSON text (such as the calls to
+ array
were not properly balanced with calls to
+ endArray
).public class JSONTokener +extends Object+
Constructor and Description | +
---|
JSONTokener(InputStream inputStream)
+Construct a JSONTokener from an InputStream.
+ |
+
JSONTokener(Reader reader)
+Construct a JSONTokener from a Reader.
+ |
+
JSONTokener(String s)
+Construct a JSONTokener from a string.
+ |
+
Modifier and Type | +Method and Description | +
---|---|
void |
+back()
+Back up one character.
+ |
+
static int |
+dehexchar(char c)
+Get the hex value of a character (base16).
+ |
+
boolean |
+end()
+Checks if the end of the input has been reached.
+ |
+
boolean |
+more()
+Determine if the source string still contains characters that next()
+ can consume.
+ |
+
char |
+next()
+Get the next character in the source string.
+ |
+
char |
+next(char c)
+Consume the next character, and check that it matches a specified
+ character.
+ |
+
String |
+next(int n)
+Get the next n characters.
+ |
+
char |
+nextClean()
+Get the next char in the string, skipping whitespace.
+ |
+
String |
+nextString(char quote)
+Return the characters up to the next close quote character.
+ |
+
String |
+nextTo(char delimiter)
+Get the text up but not including the specified character or the
+ end of line, whichever comes first.
+ |
+
String |
+nextTo(String delimiters)
+Get the text up but not including one of the specified delimiter
+ characters or the end of line, whichever comes first.
+ |
+
Object |
+nextValue()
+Get the next value.
+ |
+
char |
+skipTo(char to)
+Skip characters until the next character is the requested character.
+ |
+
JSONException |
+syntaxError(String message)
+Make a JSONException to signal a syntax error.
+ |
+
JSONException |
+syntaxError(String message,
+ Throwable causedBy)
+Make a JSONException to signal a syntax error.
+ |
+
String |
+toString()
+Make a printable string of this JSONTokener.
+ |
+
public JSONTokener(Reader reader)+
reader
- A reader.public JSONTokener(InputStream inputStream)+
inputStream
- The source.public JSONTokener(String s)+
s
- A source string.public void back() + throws JSONException+
JSONException
- Thrown if trying to step back more than 1 step
+ or if already at the start of the stringpublic static int dehexchar(char c)+
c
- A character between '0' and '9' or between 'A' and 'F' or
+ between 'a' and 'f'.public boolean end()+
public boolean more() + throws JSONException+
JSONException
- thrown if there is an error stepping forward
+ or backward while checking for more data.public char next() + throws JSONException+
JSONException
- Thrown if there is an error reading the source string.public char next(char c) + throws JSONException+
c
- The character to match.JSONException
- if the character does not match.public String next(int n) + throws JSONException+
n
- The number of characters to take.JSONException
- Substring bounds error if there are not
+ n characters remaining in the source string.public char nextClean() + throws JSONException+
JSONException
- Thrown if there is an error reading the source string.public String nextString(char quote) + throws JSONException+
quote
- The quoting character, either
+ "
(double quote) or
+ '
(single quote).JSONException
- Unterminated string.public String nextTo(char delimiter) + throws JSONException+
delimiter
- A delimiter character.JSONException
- Thrown if there is an error while searching
+ for the delimiterpublic String nextTo(String delimiters) + throws JSONException+
delimiters
- A set of delimiter characters.JSONException
- Thrown if there is an error while searching
+ for the delimiterpublic Object nextValue() + throws JSONException+
JSONException
- If syntax error.public char skipTo(char to) + throws JSONException+
to
- A character to skip to.JSONException
- Thrown if there is an error while searching
+ for the to characterpublic JSONException syntaxError(String message)+
message
- The error message.public JSONException syntaxError(String message, + Throwable causedBy)+
message
- The error message.causedBy
- The throwable that caused the error.public class JSONWriter +extends Object+
+ A JSONWriter instance provides a value
method for appending
+ values to the
+ text, and a key
+ method for adding keys before values in objects. There are array
+ and endArray
methods that make and bound array values, and
+ object
and endObject
methods which make and bound
+ object values. All of these methods return the JSONWriter instance,
+ permitting a cascade style. For example,
+ new JSONWriter(myWriter) + .object() + .key("JSON") + .value("Hello, World!") + .endObject();which writes
+ {"JSON":"Hello, World!"}+
+ The first method called must be array
or object
.
+ There are no methods for adding commas or colons. JSONWriter adds them for
+ you. Objects and arrays can be nested up to 200 levels deep.
+
+ This can sometimes be easier than using a JSONObject to build a string.
Modifier and Type | +Field and Description | +
---|---|
protected char |
+mode
+The current mode.
+ |
+
protected Appendable |
+writer
+The writer that will receive the output.
+ |
+
Constructor and Description | +
---|
JSONWriter(Appendable w)
+Make a fresh JSONWriter.
+ |
+
Modifier and Type | +Method and Description | +
---|---|
JSONWriter |
+array()
+Begin appending a new array.
+ |
+
JSONWriter |
+endArray()
+End an array.
+ |
+
JSONWriter |
+endObject()
+End an object.
+ |
+
JSONWriter |
+key(String string)
+Append a key.
+ |
+
JSONWriter |
+object()
+Begin appending a new object.
+ |
+
JSONWriter |
+value(boolean b)
+Append either the value
+true or the value
+ false . |
+
JSONWriter |
+value(double d)
+Append a double value.
+ |
+
JSONWriter |
+value(long l)
+Append a long value.
+ |
+
JSONWriter |
+value(Object object)
+Append an object value.
+ |
+
static String |
+valueToString(Object value)
+Make a JSON text of an Object value.
+ |
+
protected char mode+
protected Appendable writer+
public JSONWriter(Appendable w)+
w
- an appendable objectpublic JSONWriter array() + throws JSONException+
endArray
will be appended to this array. The
+ endArray
method must be called to mark the array's end.JSONException
- If the nesting is too deep, or if the object is
+ started in the wrong place (for example as a key or after the end of the
+ outermost array or object).public JSONWriter endArray() + throws JSONException+
array
.JSONException
- If incorrectly nested.public JSONWriter endObject() + throws JSONException+
object
.JSONException
- If incorrectly nested.public JSONWriter key(String string) + throws JSONException+
string
- A key string.JSONException
- If the key is out of place. For example, keys
+ do not belong in arrays or if the key is null.public JSONWriter object() + throws JSONException+
endObject
will be appended to this object. The
+ endObject
method must be called to mark the object's end.JSONException
- If the nesting is too deep, or if the object is
+ started in the wrong place (for example as a key or after the end of the
+ outermost array or object).public static String valueToString(Object value) + throws JSONException+
+ Warning: This method assumes that the data structure is acyclical.
value
- The value to be serialized.{
(left
+ brace) and ending with }
(right
+ brace).JSONException
- If the value is or contains an invalid number.public JSONWriter value(boolean b) + throws JSONException+
true
or the value
+ false
.b
- A boolean.JSONException
- if a called function has an errorpublic JSONWriter value(double d) + throws JSONException+
d
- A double.JSONException
- If the number is not finite.public JSONWriter value(long l) + throws JSONException+
l
- A long.JSONException
- if a called function has an errorpublic JSONWriter value(Object object) + throws JSONException+
object
- The object to append. It can be null, or a Boolean, Number,
+ String, JSONObject, or JSONArray, or an object that implements JSONString.JSONException
- If the value is out of sequence.public class Property +extends Object+
Modifier and Type | +Method and Description | +
---|---|
static JSONObject |
+toJSONObject(Properties properties)
+Converts a property file object into a JSONObject.
+ |
+
static Properties |
+toProperties(JSONObject jo)
+Converts the JSONObject into a property file object.
+ |
+
public static JSONObject toJSONObject(Properties properties) + throws JSONException+
properties
- java.util.PropertiesJSONException
- if a called function has an errorpublic static Properties toProperties(JSONObject jo) + throws JSONException+
jo
- JSONObjectJSONException
- if a called function has an errorpublic class XML +extends Object+
Modifier and Type | +Field and Description | +
---|---|
static Character |
+AMP
+The Character '&'.
+ |
+
static Character |
+APOS
+The Character '''.
+ |
+
static Character |
+BANG
+The Character '!'.
+ |
+
static Character |
+EQ
+The Character '='.
+ |
+
static Character |
+GT
+The Character
+ |
+
static Character |
+LT
+The Character '<'.
+ |
+
static String |
+NULL_ATTR
+Null attribute name
+ |
+
static Character |
+QUEST
+The Character '?'.
+ |
+
static Character |
+QUOT
+The Character '"'.
+ |
+
static Character |
+SLASH
+The Character '/'.
+ |
+
static String |
+TYPE_ATTR |
+
Modifier and Type | +Method and Description | +
---|---|
static String |
+escape(String string)
+Replace special characters with XML escapes:
+ |
+
static void |
+noSpace(String string)
+Throw an exception if the string contains whitespace.
+ |
+
static Object |
+stringToValue(String string)
+This method is the same as
+JSONObject.stringToValue(String) . |
+
static Object |
+stringToValue(String string,
+ XMLXsiTypeConverter<?> typeConverter)
+This method tries to convert the given string value to the target object
+ |
+
static JSONObject |
+toJSONObject(Reader reader)
+Convert a well-formed (but not necessarily valid) XML into a
+ JSONObject.
+ |
+
static JSONObject |
+toJSONObject(Reader reader,
+ boolean keepStrings)
+Convert a well-formed (but not necessarily valid) XML into a
+ JSONObject.
+ |
+
static JSONObject |
+toJSONObject(Reader reader,
+ XMLParserConfiguration config)
+Convert a well-formed (but not necessarily valid) XML into a
+ JSONObject.
+ |
+
static JSONObject |
+toJSONObject(String string)
+Convert a well-formed (but not necessarily valid) XML string into a
+ JSONObject.
+ |
+
static JSONObject |
+toJSONObject(String string,
+ boolean keepStrings)
+Convert a well-formed (but not necessarily valid) XML string into a
+ JSONObject.
+ |
+
static JSONObject |
+toJSONObject(String string,
+ XMLParserConfiguration config)
+Convert a well-formed (but not necessarily valid) XML string into a
+ JSONObject.
+ |
+
static String |
+toString(Object object)
+Convert a JSONObject into a well-formed, element-normal XML string.
+ |
+
static String |
+toString(Object object,
+ String tagName)
+Convert a JSONObject into a well-formed, element-normal XML string.
+ |
+
static String |
+toString(Object object,
+ String tagName,
+ XMLParserConfiguration config)
+Convert a JSONObject into a well-formed, element-normal XML string.
+ |
+
static String |
+unescape(String string)
+Removes XML escapes from the string.
+ |
+
public static final Character AMP+
public static final Character APOS+
public static final Character BANG+
public static final Character EQ+
public static final Character GT+
'>'.
public static final Character LT+
public static final Character QUEST+
public static final Character QUOT+
public static final Character SLASH+
public static final String NULL_ATTR+
public static final String TYPE_ATTR+
public static String escape(String string)+
+ & (ampersand) is replaced by &amp;
+ < (less than) is replaced by &lt;
+ > (greater than) is replaced by &gt;
+ " (double quote) is replaced by &quot;
+ ' (single quote / apostrophe) is replaced by &apos;
+
string
- The string to be escaped.public static String unescape(String string)+
string
- string to remove escapes frompublic static void noSpace(String string) + throws JSONException+
string
- A string.JSONException
- Thrown if the string contains whitespace or is empty.public static Object stringToValue(String string, + XMLXsiTypeConverter<?> typeConverter)+
string
- String to converttypeConverter
- value converter to convert string to integer, boolean e.t.cpublic static Object stringToValue(String string)+
JSONObject.stringToValue(String)
.string
- String to convertpublic static JSONObject toJSONObject(String string) + throws JSONException+
+ <[ [ ]]>
+ are ignored.string
- The source string.JSONException
- Thrown if there is an errors while parsing the stringpublic static JSONObject toJSONObject(Reader reader) + throws JSONException+
+ <[ [ ]]>
+ are ignored.reader
- The XML source reader.JSONException
- Thrown if there is an errors while parsing the stringpublic static JSONObject toJSONObject(Reader reader, + boolean keepStrings) + throws JSONException+
+ <[ [ ]]>
+ are ignored.
+
+ All values are converted as strings, for 1, 01, 29.0 will not be coerced to
+ numbers but will instead be the exact value as seen in the XML document.reader
- The XML source reader.keepStrings
- If true, then values will not be coerced into boolean
+ or numeric values and will instead be left as stringsJSONException
- Thrown if there is an errors while parsing the stringpublic static JSONObject toJSONObject(Reader reader, + XMLParserConfiguration config) + throws JSONException+
+ <[ [ ]]>
+ are ignored.
+
+ All values are converted as strings, for 1, 01, 29.0 will not be coerced to
+ numbers but will instead be the exact value as seen in the XML document.reader
- The XML source reader.config
- Configuration options for the parserJSONException
- Thrown if there is an errors while parsing the stringpublic static JSONObject toJSONObject(String string, + boolean keepStrings) + throws JSONException+
+ <[ [ ]]>
+ are ignored.
+
+ All values are converted as strings, for 1, 01, 29.0 will not be coerced to
+ numbers but will instead be the exact value as seen in the XML document.string
- The source string.keepStrings
- If true, then values will not be coerced into boolean
+ or numeric values and will instead be left as stringsJSONException
- Thrown if there is an errors while parsing the stringpublic static JSONObject toJSONObject(String string, + XMLParserConfiguration config) + throws JSONException+
+ <[ [ ]]>
+ are ignored.
+
+ All values are converted as strings, for 1, 01, 29.0 will not be coerced to
+ numbers but will instead be the exact value as seen in the XML document.string
- The source string.config
- Configuration options for the parser.JSONException
- Thrown if there is an errors while parsing the stringpublic static String toString(Object object) + throws JSONException+
object
- A JSONObject.JSONException
- Thrown if there is an error parsing the stringpublic static String toString(Object object, + String tagName)+
object
- A JSONObject.tagName
- The optional name of the enclosing tag.JSONException
- Thrown if there is an error parsing the stringpublic static String toString(Object object, + String tagName, + XMLParserConfiguration config) + throws JSONException+
object
- A JSONObject.tagName
- The optional name of the enclosing tag.config
- Configuration that can control output to XML.JSONException
- Thrown if there is an error parsing the stringpublic class XMLParserConfiguration +extends Object+
Modifier and Type | +Field and Description | +
---|---|
static XMLParserConfiguration |
+KEEP_STRINGS
+Original configuration of the XML Parser except that values are kept as strings.
+ |
+
static XMLParserConfiguration |
+ORIGINAL
+Original Configuration of the XML Parser.
+ |
+
Constructor and Description | +
---|
XMLParserConfiguration()
+Default parser configuration.
+ |
+
XMLParserConfiguration(boolean keepStrings)
+Deprecated.
+
+This constructor has been deprecated in favor of using the new builder
+ pattern for the configuration.
+ This constructor may be removed in a future release.
+ |
+
XMLParserConfiguration(boolean keepStrings,
+ String cDataTagName)
+Deprecated.
+
+This constructor has been deprecated in favor of using the new builder
+ pattern for the configuration.
+ This constructor may be removed in a future release.
+ |
+
XMLParserConfiguration(boolean keepStrings,
+ String cDataTagName,
+ boolean convertNilAttributeToNull)
+Deprecated.
+
+This constructor has been deprecated in favor of using the new builder
+ pattern for the configuration.
+ This constructor may be removed or marked private in a future release.
+ |
+
XMLParserConfiguration(String cDataTagName)
+Deprecated.
+
+This constructor has been deprecated in favor of using the new builder
+ pattern for the configuration.
+ This constructor may be removed in a future release.
+ |
+
Modifier and Type | +Method and Description | +
---|---|
protected XMLParserConfiguration |
+clone()
+Provides a new instance of the same configuration.
+ |
+
String |
+getcDataTagName()
+The name of the key in a JSON Object that indicates a CDATA section.
+ |
+
Map<String,XMLXsiTypeConverter<?>> |
+getXsiTypeMap()
+When parsing the XML into JSON, specifies that the values with attribute xsi:type
+ will be converted to target type defined to client in this configuration
+
+Map<String, XMLXsiTypeConverter<?>> to parse values with attribute
+ xsi:type="integer" as integer, xsi:type="string" as string |
+
boolean |
+isConvertNilAttributeToNull()
+When parsing the XML into JSON, specifies if values with attribute xsi:nil="true"
+ should be kept as attribute(
+false ), or they should be converted to
+ null (true ) |
+
boolean |
+isKeepStrings()
+When parsing the XML into JSON, specifies if values should be kept as strings (
+true ), or if
+ they should try to be guessed into JSON values (numeric, boolean, string) |
+
XMLParserConfiguration |
+withcDataTagName(String newVal)
+The name of the key in a JSON Object that indicates a CDATA section.
+ |
+
XMLParserConfiguration |
+withConvertNilAttributeToNull(boolean newVal)
+When parsing the XML into JSON, specifies if values with attribute xsi:nil="true"
+ should be kept as attribute(
+false ), or they should be converted to
+ null (true ) |
+
XMLParserConfiguration |
+withKeepStrings(boolean newVal)
+When parsing the XML into JSON, specifies if values should be kept as strings (
+true ), or if
+ they should try to be guessed into JSON values (numeric, boolean, string) |
+
XMLParserConfiguration |
+withXsiTypeMap(Map<String,XMLXsiTypeConverter<?>> xsiTypeMap)
+When parsing the XML into JSON, specifies that the values with attribute xsi:type
+ will be converted to target type defined to client in this configuration
+
+Map<String, XMLXsiTypeConverter<?>> to parse values with attribute
+ xsi:type="integer" as integer, xsi:type="string" as string |
+
public static final XMLParserConfiguration ORIGINAL+
public static final XMLParserConfiguration KEEP_STRINGS+
public XMLParserConfiguration()+
@Deprecated +public XMLParserConfiguration(boolean keepStrings)+
keepStrings
- true
to parse all values as string.
+ false
to try and convert XML string values into a JSON value.@Deprecated +public XMLParserConfiguration(String cDataTagName)+
null
to
+ disable CDATA processingcDataTagNamenull
- to disable CDATA processing. Any other value
+ to use that value as the JSONObject key name to process as CDATA.@Deprecated +public XMLParserConfiguration(boolean keepStrings, + String cDataTagName)+
keepStrings
- true
to parse all values as string.
+ false
to try and convert XML string values into a JSON value.cDataTagNamenull
- to disable CDATA processing. Any other value
+ to use that value as the JSONObject key name to process as CDATA.@Deprecated +public XMLParserConfiguration(boolean keepStrings, + String cDataTagName, + boolean convertNilAttributeToNull)+
keepStrings
- true
to parse all values as string.
+ false
to try and convert XML string values into a JSON value.cDataTagName
- null
to disable CDATA processing. Any other value
+ to use that value as the JSONObject key name to process as CDATA.convertNilAttributeToNull
- true
to parse values with attribute xsi:nil="true" as null.
+ false
to parse values with attribute xsi:nil="true" as {"xsi:nil":true}.protected XMLParserConfiguration clone()+
public boolean isKeepStrings()+
true
), or if
+ they should try to be guessed into JSON values (numeric, boolean, string)keepStrings
configuration value.public XMLParserConfiguration withKeepStrings(boolean newVal)+
true
), or if
+ they should try to be guessed into JSON values (numeric, boolean, string)newVal
- new value to use for the keepStrings
configuration option.public String getcDataTagName()+
null
to indicate no CDATA
+ processing.cDataTagName
configuration value.public XMLParserConfiguration withcDataTagName(String newVal)+
null
to indicate no CDATA
+ processing.newVal
- new value to use for the cDataTagName
configuration option.public boolean isConvertNilAttributeToNull()+
false
), or they should be converted to
+ null
(true
)convertNilAttributeToNull
configuration value.public XMLParserConfiguration withConvertNilAttributeToNull(boolean newVal)+
false
), or they should be converted to
+ null
(true
)newVal
- new value to use for the convertNilAttributeToNull
configuration option.public Map<String,XMLXsiTypeConverter<?>> getXsiTypeMap()+
Map<String, XMLXsiTypeConverter<?>>
to parse values with attribute
+ xsi:type="integer" as integer, xsi:type="string" as stringxsiTypeMap
unmodifiable configuration map.public XMLParserConfiguration withXsiTypeMap(Map<String,XMLXsiTypeConverter<?>> xsiTypeMap)+
Map<String, XMLXsiTypeConverter<?>>
to parse values with attribute
+ xsi:type="integer" as integer, xsi:type="string" as stringxsiTypeMap
- new HashMap<String, XMLXsiTypeConverter<?>>()
to parse values with attribute
+ xsi:type="integer" as integer, xsi:type="string" as stringpublic class XMLTokener +extends JSONTokener+
Modifier and Type | +Field and Description | +
---|---|
static HashMap<String,Character> |
+entity
+The table of entity values.
+ |
+
Constructor and Description | +
---|
XMLTokener(Reader r)
+Construct an XMLTokener from a Reader.
+ |
+
XMLTokener(String s)
+Construct an XMLTokener from a string.
+ |
+
Modifier and Type | +Method and Description | +
---|---|
String |
+nextCDATA()
+Get the text in the CDATA block.
+ |
+
Object |
+nextContent()
+Get the next XML outer token, trimming whitespace.
+ |
+
Object |
+nextEntity(char ampersand)
+{@code
+ Return the next entity.
+ |
+
Object |
+nextMeta()
+{@code
+ Returns the next XML meta token.
+ |
+
Object |
+nextToken()
+{@code
+ Get the next XML Token.
+ |
+
void |
+skipPast(String to)
+Skip characters until past the requested string.
+ |
+
back, dehexchar, end, more, next, next, next, nextClean, nextString, nextTo, nextTo, nextValue, skipTo, syntaxError, syntaxError, toString
public XMLTokener(Reader r)+
r
- A source reader.public XMLTokener(String s)+
s
- A source string.public String nextCDATA() + throws JSONException+
]]>
.JSONException
- If the ]]>
is not found.public Object nextContent() + throws JSONException+
'<'
character which begins a markup
+ tag, and the content
+ text between markup tags. '<'
Character, or null if
+ there is no more source text.JSONException
- if a called function has an errorpublic Object nextEntity(char ampersand) + throws JSONException+
+ Return the next entity. These entities are translated to Characters:
+ & ' > < ".
+
ampersand
- An ampersand character.JSONException
- If missing ';' in XML entity.public Object nextMeta() + throws JSONException+
+ Returns the next XML meta token. This is used for skipping over <!...>
+ and <?...?> structures.
+
Syntax characters (< > / = ! ?) are returned as
+ Character, and strings and names are returned as Boolean. We don't care
+ what the values actually are.
+
JSONException
- If a string is not properly closed or if the XML
+ is badly structured.public Object nextToken() + throws JSONException+
+ Get the next XML Token. These tokens are found inside of angle
+ brackets. It may be one of these characters: / > = ! ? or it
+ may be a string wrapped in single quotes or double quotes, or it may be a
+ name.
+
JSONException
- If the XML is not well formed.public void skipPast(String to)+
to
- A string to skip past.T
- return type of convert methodpublic interface XMLXsiTypeConverter<T>
++ XML Sample ++ <root> + <asString xsi:type="string">12345</asString> + <asInt xsi:type="integer">54321</asInt> + </root> +
+ JSON Output ++ { + "root" : { + "asString" : "12345", + "asInt": 54321 + } + } +
+ + Usage ++ Map<String, XMLXsiTypeConverter<?>> xsiTypeMap = new HashMap<String, XMLXsiTypeConverter<?>>(); + xsiTypeMap.put("string", new XMLXsiTypeConverter<String>() { + @Override public String convert(final String value) { + return value; + } + }); + xsiTypeMap.put("integer", new XMLXsiTypeConverter<Integer>() { + @Override public Integer convert(final String value) { + return Integer.valueOf(value); + } + }); +
+
Modifier and Type | +Method and Description | +
---|---|
T |
+convert(String value) |
+
Interface | +Description | +
---|---|
JSONString | +
+ The
+JSONString interface allows a toJSONString()
+ method so that a class can change the behavior of
+ JSONObject.toString() , JSONArray.toString() ,
+ and JSONWriter.value( Object) . |
+
XMLXsiTypeConverter<T> | +
+ Type conversion configuration interface to be used with xsi:type attributes.
+ |
+
Class | +Description | +
---|---|
CDL | +
+ This provides static methods to convert comma delimited text into a
+ JSONArray, and to convert a JSONArray into comma delimited text.
+ |
+
Cookie | +
+ Convert a web browser cookie specification to a JSONObject and back.
+ |
+
CookieList | +
+ Convert a web browser cookie list string to a JSONObject and back.
+ |
+
HTTP | +
+ Convert an HTTP header to a JSONObject and back.
+ |
+
HTTPTokener | +
+ The HTTPTokener extends the JSONTokener to provide additional methods
+ for the parsing of HTTP headers.
+ |
+
JSONArray | +
+ A JSONArray is an ordered sequence of values.
+ |
+
JSONML | +
+ This provides static methods to convert an XML text into a JSONArray or
+ JSONObject, and to covert a JSONArray or JSONObject into an XML text using
+ the JsonML transform.
+ |
+
JSONObject | +
+ A JSONObject is an unordered collection of name/value pairs.
+ |
+
JSONPointer | +
+ A JSON Pointer is a simple query language defined for JSON documents by
+ RFC 6901.
+ |
+
JSONPointer.Builder | +
+ This class allows the user to build a JSONPointer in steps, using
+ exactly one segment in each step.
+ |
+
JSONStringer | +
+ JSONStringer provides a quick and convenient way of producing JSON text.
+ |
+
JSONTokener | +
+ A JSONTokener takes a source string and extracts characters and tokens from
+ it.
+ |
+
JSONWriter | +
+ JSONWriter provides a quick and convenient way of producing JSON text.
+ |
+
Property | +
+ Converts a Property file data into JSONObject and back.
+ |
+
XML | +
+ This provides static methods to convert an XML text into a JSONObject, and to
+ covert a JSONObject into an XML text.
+ |
+
XMLParserConfiguration | +
+ Configuration object for the XML parser.
+ |
+
XMLTokener | +
+ The XMLTokener extends the JSONTokener to provide additional methods
+ for the parsing of XML texts.
+ |
+
Exception | +Description | +
---|---|
JSONException | +
+ The JSONException is thrown by the JSON.org classes when things are amiss.
+ |
+
JSONPointerException | +
+ The JSONPointerException is thrown by
+JSONPointer if an error occurs
+ during evaluating a pointer. |
+
Annotation Type | +Description | +
---|---|
JSONPropertyIgnore | ++ |
JSONPropertyName | ++ |