|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap
java.util.HashMap
com.ibm.json.java.JSONObject
public class JSONObject
Models a JSON Object.
Extension of HashMap that only allows String keys, and values which are JSON-able.
JSON-able values are: null, and instances of String, Boolean, Number, JSONObject and JSONArray.
Instances of this class are not thread-safe.
Constructor Summary | |
---|---|
JSONObject()
Create a new instance of this class. |
Method Summary | |
---|---|
static boolean |
isValidObject(java.lang.Object object)
Return whether the object is a valid value for a property. |
static boolean |
isValidType(java.lang.Class clazz)
Return whether the class is a valid type of value for a property. |
static JSONObject |
parse(java.io.InputStream is)
Convert a stream of JSON text into object form. |
static JSONObject |
parse(java.io.Reader reader)
Convert a stream (in reader form) of JSON text into object form. |
static JSONObject |
parse(java.lang.String str)
Convert a String of JSON text into object form. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
(non-Javadoc) |
java.lang.String |
serialize()
Convert this object into a String of JSON text. |
java.lang.String |
serialize(boolean verbose)
Convert this object into a String of JSON text, specifying verbosity. |
void |
serialize(java.io.OutputStream os)
Convert this object into a stream of JSON text. |
void |
serialize(java.io.OutputStream os,
boolean verbose)
Convert this object into a stream of JSON text. |
void |
serialize(java.io.Writer writer)
Convert this object into a stream of JSON text. |
void |
serialize(java.io.Writer writer,
boolean verbose)
Convert this object into a stream of JSON text, specifying verbosity. |
java.lang.String |
toString()
Over-ridden toString() method. |
Methods inherited from class java.util.HashMap |
---|
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, putAll, remove, size, values |
Methods inherited from class java.util.AbstractMap |
---|
equals, hashCode |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Map |
---|
equals, hashCode |
Constructor Detail |
---|
public JSONObject()
Method Detail |
---|
public static boolean isValidObject(java.lang.Object object)
object
- The object to check for validity as a JSON property value.public static boolean isValidType(java.lang.Class clazz)
clazz
- The class type to check for validity as a JSON object type.public static JSONObject parse(java.io.Reader reader) throws java.io.IOException
reader
- The reader from which the JSON data is read.
IOEXception
- Thrown if an underlying IO error from the reader occurs, or if malformed JSON is read,
java.io.IOException
public static JSONObject parse(java.lang.String str) throws java.io.IOException
str
- The JSON string to parse into a Java Object.
IOEXception
- Thrown if malformed JSON is read,
java.io.IOException
public static JSONObject parse(java.io.InputStream is) throws java.io.IOException
is
- The inputStream from which to read the JSON. It will assume the input stream is in UTF-8 and read it as such.
IOEXception
- Thrown if an underlying IO error from the stream occurs, or if malformed JSON is read,
java.io.IOException
public void serialize(java.io.OutputStream os) throws java.io.IOException
serialize
in interface JSONArtifact
os
- The output stream to serialize data to.
java.io.IOException
- Thrown on IO errors during serialization.public void serialize(java.io.OutputStream os, boolean verbose) throws java.io.IOException
serialize
in interface JSONArtifact
os
- The output stream to serialize data to.verbose
- Whether or not to write the JSON text in a verbose format.
java.io.IOException
- Thrown on IO errors during serialization.public void serialize(java.io.Writer writer) throws java.io.IOException
serialize
in interface JSONArtifact
writer
- The writer which to serialize the JSON text to.
java.io.IOException
- Thrown on IO errors during serialization.public void serialize(java.io.Writer writer, boolean verbose) throws java.io.IOException
serialize
in interface JSONArtifact
writer
- The writer which to serialize the JSON text to.
java.io.IOException
- Thrown on IO errors during serialization.public java.lang.String serialize(boolean verbose) throws java.io.IOException
serialize
in interface JSONArtifact
verbose
- Whether or not to serialize in compressed for formatted Strings.
java.io.IOException
- Thrown on IO errors during serialization.public java.lang.String serialize() throws java.io.IOException
serialize
in interface JSONArtifact
java.io.IOException
- Thrown on IO errors during serialization.public java.lang.Object put(java.lang.Object key, java.lang.Object value)
put
in interface java.util.Map
put
in class java.util.HashMap
HashMap.put(java.lang.Object, java.lang.Object)
public java.lang.String toString()
toString
in class java.util.AbstractMap
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |