Package net.sf.json
Interface JSON
-
- All Superinterfaces:
java.io.Serializable
- All Known Implementing Classes:
JSONArray
,JSONNull
,JSONObject
public interface JSON extends java.io.Serializable
Marker interface, identifies a valid JSON value.
A JSON value may be aJSONObject
, aJSONArray
or aJSONNull
.- Author:
- Andres Almiray
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
isArray()
Returns true if this object is a JSONArray, false otherwise.boolean
isEmpty()
Returns true if this object has no elements or keys.int
size()
Returns the number of properties in an object or the size of the array.java.lang.String
toString(int indentFactor)
Make a prettyprinted JSON text.java.lang.String
toString(int indentFactor, int indent)
Make a prettyprinted JSON text.java.io.Writer
write(java.io.Writer writer)
Write the contents as JSON text to a writer.java.io.Writer
writeCanonical(java.io.Writer w)
Writes the canonicalized form of this JSON object.
-
-
-
Method Detail
-
isArray
boolean isArray()
Returns true if this object is a JSONArray, false otherwise.
-
isEmpty
boolean isEmpty()
Returns true if this object has no elements or keys.- Throws:
JSONException
- if called on a 'null' object
-
size
int size()
Returns the number of properties in an object or the size of the array.- Returns:
- the size of an json object or array
- Throws:
JSONException
- if called on a 'null' object
-
toString
java.lang.String toString(int indentFactor)
Make a prettyprinted JSON text.Warning: This method assumes that the data structure is acyclical.
- Parameters:
indentFactor
- The number of spaces to add to each level of indentation.- Returns:
- a printable, displayable, portable, transmittable representation
of the object, beginning with
{
(left brace) and ending with}
(right brace). - Throws:
JSONException
- If the object contains an invalid number.
-
toString
java.lang.String toString(int indentFactor, int indent)
Make a prettyprinted JSON text.Warning: This method assumes that the data structure is acyclical.
- Parameters:
indentFactor
- The number of spaces to add to each level of indentation.indent
- The indentation of the top level.- Returns:
- a printable, displayable, transmittable representation of the
object, beginning with
{
(left brace) and ending with}
(right brace). - Throws:
JSONException
- If the object contains an invalid number.
-
write
java.io.Writer write(java.io.Writer writer) throws java.io.IOException
Write the contents as JSON text to a writer. For compactness, no whitespace is added.Warning: This method assumes that the data structure is acyclical.
- Returns:
- The writer.
- Throws:
JSONException
java.io.IOException
-
writeCanonical
java.io.Writer writeCanonical(java.io.Writer w) throws java.io.IOException
Writes the canonicalized form of this JSON object.- Throws:
java.io.IOException
-
-