ikrs.json
Interface JSONValue

All Known Subinterfaces:
JSONRPCError, JSONRPCRequest, JSONRPCResponse
All Known Implementing Classes:
AbstractJSONValue, DefaultJSONRPCError, DefaultJSONRPCRequest, DefaultJSONRPCResponse, JSONArray, JSONBoolean, JSONNull, JSONNumber, JSONObject, JSONString

public interface JSONValue


Field Summary
static JSONBoolean FALSE
          This is a public shared instance that should be used for JSON false.
static JSONNull NULL
          This is a public shared instance that should be used for JSON null.
static JSONBoolean TRUE
          This is a public shared instance that should be used for JSON true.
static int TYPE_ARRAY
          The type constant for arrays.
static int TYPE_BOOLEAN
          The type constant for boolean values.
static int TYPE_NULL
          The constant indicating null.
static int TYPE_NUMBER
          The type constant for numbers.
static int TYPE_OBJECT
          The type constant for objects.
static int TYPE_STRING
          The type constant for strings.
 
Method Summary
 JSONArray asJSONArray()
          This method tries to convert this JSONValue into a JSONArray.
 JSONBoolean asJSONBoolean()
          This method tries to convert this JSONValue into a JSONBoolean.
 JSONNumber asJSONNumber()
          This method tries to convert this JSONValue into a JSONNumber.
 JSONObject asJSONObject()
          This method tries to convert this JSONValue into a JSONObject.
 JSONString asJSONString()
          This method tries to convert this JSONValue into a JSONString.
 java.util.List<JSONValue> getArray()
          Get the array value as a List from this JSON value.
 java.lang.Boolean getBoolean()
          Get the boolean from this JSON value.
 java.lang.Number getNumber()
          Get the number from this JSON value.
 java.util.Map<java.lang.String,JSONValue> getObject()
          Get the object value as a Map from this JSON value.
 java.lang.String getString()
          Get the string from this JSON value.
 boolean isArray()
          This method indicates if this JSON value is an array.
 boolean isBoolean()
          This method indicates if this JSON value is a boolean.
 boolean isNull()
          This method indicates if this is JSON NULL.
 boolean isNumber()
          This method indicates if this JSON value is a number.
 boolean isObject()
          This method indicates if this JSON value is an object.
 boolean isString()
          This method indicates if this JSON value is a string.
 java.lang.String toJSONString()
          Converts this JSON value into a valid JSON string.
 void write(java.io.Writer writer)
          This method MUST write a valid JSON value to the passed writer.
 

Field Detail

NULL

static final JSONNull NULL
This is a public shared instance that should be used for JSON null.


TRUE

static final JSONBoolean TRUE
This is a public shared instance that should be used for JSON true.


FALSE

static final JSONBoolean FALSE
This is a public shared instance that should be used for JSON false.


TYPE_NULL

static final int TYPE_NULL
The constant indicating null.

See Also:
Constant Field Values

TYPE_NUMBER

static final int TYPE_NUMBER
The type constant for numbers.

See Also:
Constant Field Values

TYPE_BOOLEAN

static final int TYPE_BOOLEAN
The type constant for boolean values.

See Also:
Constant Field Values

TYPE_STRING

static final int TYPE_STRING
The type constant for strings.

See Also:
Constant Field Values

TYPE_ARRAY

static final int TYPE_ARRAY
The type constant for arrays.

See Also:
Constant Field Values

TYPE_OBJECT

static final int TYPE_OBJECT
The type constant for objects.

See Also:
Constant Field Values
Method Detail

isNull

boolean isNull()
This method indicates if this is JSON NULL.

Returns:
true if this JSON value is NULL (null).

isNumber

boolean isNumber()
This method indicates if this JSON value is a number.

Returns:
true if this value represents a number.

isBoolean

boolean isBoolean()
This method indicates if this JSON value is a boolean.

Returns:
true if this value represents a boolean value.

isString

boolean isString()
This method indicates if this JSON value is a string.

Returns:
true if this value represents a string.

isArray

boolean isArray()
This method indicates if this JSON value is an array.

Returns:
true if this value represents an array.

isObject

boolean isObject()
This method indicates if this JSON value is an object.

Returns:
true if this value represents an array.

getNumber

java.lang.Number getNumber()
                           throws JSONException
Get the number from this JSON value.

Returns:
The number from this JSON value.
Throws:
JSONException - If this value does not represent a number.

getBoolean

java.lang.Boolean getBoolean()
                             throws JSONException
Get the boolean from this JSON value.

Returns:
The boolean value from this JSON value.
Throws:
JSONException - If this value does not represent a boolean value.

getString

java.lang.String getString()
                           throws JSONException
Get the string from this JSON value.

Returns:
The string value from this JSON value.
Throws:
JSONException - If this value does not represent a string.

getArray

java.util.List<JSONValue> getArray()
                                   throws JSONException
Get the array value as a List from this JSON value.

Returns:
The array from this JSON value. The array is returned as a Mist.
Throws:
JSONException - If this value does not represent an array.

getObject

java.util.Map<java.lang.String,JSONValue> getObject()
                                                    throws JSONException
Get the object value as a Map from this JSON value.

Returns:
The object from this JSON value. The object is returned as a Map.
Throws:
JSONException - If this value does not represent an object.

asJSONBoolean

JSONBoolean asJSONBoolean()
                          throws JSONException
This method tries to convert this JSONValue into a JSONBoolean. If that is not possible (because the contained value does not represent a boolean in any way) the method will throw an JSONException.

Returns:
This JSON value as a JSON boolean.
Throws:
JSONException - If this value is not convertible to a boolean.

asJSONNumber

JSONNumber asJSONNumber()
                        throws JSONException
This method tries to convert this JSONValue into a JSONNumber. If that is not possible (because the contained value does not represent a number in any way) the method will throw an JSONException.

Returns:
This JSON value as a JSON number.
Throws:
JSONException - If this value is not convertible to a number.

asJSONString

JSONString asJSONString()
                        throws JSONException
This method tries to convert this JSONValue into a JSONString. If that is not possible (because the contained value does not represent a string in any way) the method will throw an JSONException. Note: due to the fact that JSON is usually represented by a string EACH JSON VALUE SHOULD BE CONVERTIBLE TO A STRING.

Returns:
This JSON value as a JSON string.
Throws:
JSONException - If this value is not convertible to a boolean.

asJSONArray

JSONArray asJSONArray()
                      throws JSONException
This method tries to convert this JSONValue into a JSONArray. If that is not possible (because the contained value does not represent an array in any way) the method will throw an JSONException.

Returns:
This JSON value as a JSON array.
Throws:
JSONException - If this value is not convertible to an array.

asJSONObject

JSONObject asJSONObject()
                        throws JSONException
This method tries to convert this JSONValue into a JSONObject. If that is not possible (because the contained value does not represent an object in any way) the method will throw an JSONException.

Returns:
This JSON value as a JSON object.
Throws:
JSONException - If this value is not convertible to an object.

write

void write(java.io.Writer writer)
           throws java.io.IOException
This method MUST write a valid JSON value to the passed writer.

Parameters:
writer - The writer to write to.
Throws:
java.io.IOException - If any IO errors occur.

toJSONString

java.lang.String toJSONString()
Converts this JSON value into a valid JSON string.

Returns:
This value as a JSON string.