public class JSONNode extends DefaultMutableTreeNode
| Modifier and Type | Class and Description |
|---|---|
static class |
JSONNode.NodeType
The type of a node.
|
EMPTY_ENUMERATION| Constructor and Description |
|---|
JSONNode()
Initializes the root container.
|
JSONNode(String name,
Boolean value)
Initializes the primitive container.
|
JSONNode(String name,
Double value)
Initializes the primitive container.
|
JSONNode(String name,
Integer value)
Initializes the primitive container.
|
JSONNode(String name,
String value)
Initializes the primitive container.
|
| Modifier and Type | Method and Description |
|---|---|
JSONNode |
addArray(String name)
Adds an array child to the object.
|
JSONNode |
addArrayElement(Object value)
Adds an array element child to the array.
|
JSONNode |
addNull(String name)
Adds a "null" child to the object.
|
JSONNode |
addNullArrayElement()
Adds a null array element child to the array.
|
JSONNode |
addObject(String name)
Adds an object child to the object.
|
JSONNode |
addPrimitive(String name,
Boolean value)
Adds a key-value child to the object.
|
JSONNode |
addPrimitive(String name,
Double value)
Adds a key-value child to the object.
|
JSONNode |
addPrimitive(String name,
Integer value)
Adds a key-value child to the object.
|
JSONNode |
addPrimitive(String name,
String value)
Adds a key-value child to the object.
|
JSONNode |
getChild(String name)
Returns the child with the given name.
|
String |
getName()
Returns the name of the node.
|
JSONNode.NodeType |
getNodeType()
Returns the type of the container.
|
Object |
getValue()
Returns the stored value.
|
Object |
getValue(Object defValue)
Returns the stored value.
|
boolean |
hasChild(String name)
Checks whether the node has a child with the given name.
|
boolean |
isAnonymous()
Checks whether the node is anonymous.
|
boolean |
isArray()
Returns wether the node is an array.
|
boolean |
isObject()
Returns wether the node is an object.
|
boolean |
isPrimitive()
Returns whether the node stores a primitive value or a an array/object.
|
static void |
main(String[] args)
Only for testing.
|
static JSONNode |
read(Reader reader)
Reads the JSON object from the given reader.
|
String |
toString()
Returns a string representation of the node.
|
void |
toString(StringBuffer buffer)
Dumps the node structure into JSON format.
|
add, breadthFirstEnumeration, children, clone, depthFirstEnumeration, getAllowsChildren, getChildAfter, getChildAt, getChildBefore, getChildCount, getDepth, getFirstChild, getFirstLeaf, getIndex, getLastChild, getLastLeaf, getLeafCount, getLevel, getNextLeaf, getNextNode, getNextSibling, getParent, getPath, getPreviousLeaf, getPreviousNode, getPreviousSibling, getRoot, getSharedAncestor, getSiblingCount, getUserObject, getUserObjectPath, insert, isLeaf, isNodeAncestor, isNodeChild, isNodeDescendant, isNodeRelated, isNodeSibling, isRoot, pathFromAncestorEnumeration, postorderEnumeration, preorderEnumeration, remove, remove, removeAllChildren, removeFromParent, setAllowsChildren, setParent, setUserObjectpublic JSONNode()
public JSONNode(String name, Boolean value)
name - the namevalue - the primitive valuepublic JSONNode(String name, Integer value)
name - the namevalue - the primitive valuepublic JSONNode(String name, Double value)
name - the namevalue - the primitive valuepublic boolean isAnonymous()
public String getName()
public Object getValue()
public Object getValue(Object defValue)
defValue - the default value, if value is nullpublic boolean isPrimitive()
public boolean isArray()
public boolean isObject()
public JSONNode.NodeType getNodeType()
public JSONNode addNull(String name)
name - the name of the null valuepublic JSONNode addPrimitive(String name, Boolean value)
name - the name of the pairvalue - the valuepublic JSONNode addPrimitive(String name, Integer value)
name - the name of the pairvalue - the valuepublic JSONNode addPrimitive(String name, Double value)
name - the name of the pairvalue - the valuepublic JSONNode addPrimitive(String name, String value)
name - the name of the pairvalue - the valuepublic JSONNode addArray(String name)
name - the name of the pairpublic JSONNode addNullArrayElement()
public JSONNode addArrayElement(Object value)
value - the value of the element arraypublic JSONNode addObject(String name)
name - the name of the pairpublic boolean hasChild(String name)
name - the name of the childpublic JSONNode getChild(String name)
name - the name of the childpublic void toString(StringBuffer buffer)
buffer - the buffer to add the data topublic String toString()
toString in class DefaultMutableTreeNodepublic static JSONNode read(Reader reader) throws Exception
reader - the reader to read the JSON object fromException - if parsing failsCopyright © 2013 University of Waikato, Hamilton, NZ. All Rights Reserved.