public class JSONNode
extends javax.swing.tree.DefaultMutableTreeNode
| Modifier and Type | Class and Description |
|---|---|
static class |
JSONNode.NodeType
The type of a node.
|
| Constructor and Description |
|---|
JSONNode()
Initializes the root container.
|
JSONNode(java.lang.String name,
java.lang.Boolean value)
Initializes the primitive container.
|
JSONNode(java.lang.String name,
java.lang.Double value)
Initializes the primitive container.
|
JSONNode(java.lang.String name,
java.lang.Integer value)
Initializes the primitive container.
|
JSONNode(java.lang.String name,
java.lang.String value)
Initializes the primitive container.
|
| Modifier and Type | Method and Description |
|---|---|
JSONNode |
addArray(java.lang.String name)
Adds an array child to the object.
|
JSONNode |
addArrayElement(java.lang.Object value)
Adds an array element child to the array.
|
JSONNode |
addNull(java.lang.String name)
Adds a "null" child to the object.
|
JSONNode |
addNullArrayElement()
Adds a null array element child to the array.
|
JSONNode |
addObject(java.lang.String name)
Adds an object child to the object.
|
JSONNode |
addObjectArrayElement()
Add a key-value object child into the array
|
JSONNode |
addPrimitive(java.lang.String name,
java.lang.Boolean value)
Adds a key-value child to the object.
|
JSONNode |
addPrimitive(java.lang.String name,
java.lang.Double value)
Adds a key-value child to the object.
|
JSONNode |
addPrimitive(java.lang.String name,
java.lang.Integer value)
Adds a key-value child to the object.
|
JSONNode |
addPrimitive(java.lang.String name,
java.lang.String value)
Adds a key-value child to the object.
|
JSONNode |
getChild(java.lang.String name)
Returns the child with the given name.
|
java.lang.String |
getName()
Returns the name of the node.
|
JSONNode.NodeType |
getNodeType()
Returns the type of the container.
|
java.lang.Object |
getValue()
Returns the stored value.
|
java.lang.Object |
getValue(java.lang.Object defValue)
Returns the stored value.
|
boolean |
hasChild(java.lang.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(java.lang.String[] args)
Only for testing.
|
static JSONNode |
read(java.io.Reader reader)
Reads the JSON object from the given reader.
|
java.lang.String |
toString()
Returns a string representation of the node.
|
void |
toString(java.lang.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(java.lang.String name,
java.lang.Boolean value)
name - the namevalue - the primitive valuepublic JSONNode(java.lang.String name,
java.lang.Integer value)
name - the namevalue - the primitive valuepublic JSONNode(java.lang.String name,
java.lang.Double value)
name - the namevalue - the primitive valuepublic JSONNode(java.lang.String name,
java.lang.String value)
name - the namevalue - the primitive valuepublic boolean isAnonymous()
public java.lang.String getName()
public java.lang.Object getValue()
public java.lang.Object getValue(java.lang.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(java.lang.String name)
name - the name of the null valuepublic JSONNode addPrimitive(java.lang.String name, java.lang.Boolean value)
name - the name of the pairvalue - the valuepublic JSONNode addPrimitive(java.lang.String name, java.lang.Integer value)
name - the name of the pairvalue - the valuepublic JSONNode addPrimitive(java.lang.String name, java.lang.Double value)
name - the name of the pairvalue - the valuepublic JSONNode addPrimitive(java.lang.String name, java.lang.String value)
name - the name of the pairvalue - the valuepublic JSONNode addArray(java.lang.String name)
name - the name of the pairpublic JSONNode addNullArrayElement()
public JSONNode addObjectArrayElement()
public JSONNode addArrayElement(java.lang.Object value)
value - the value of the element arraypublic JSONNode addObject(java.lang.String name)
name - the name of the pairpublic boolean hasChild(java.lang.String name)
name - the name of the childpublic JSONNode getChild(java.lang.String name)
name - the name of the childpublic void toString(java.lang.StringBuffer buffer)
buffer - the buffer to add the data topublic java.lang.String toString()
toString in class javax.swing.tree.DefaultMutableTreeNodepublic static JSONNode read(java.io.Reader reader) throws java.lang.Exception
reader - the reader to read the JSON object fromjava.lang.Exception - if parsing failspublic static void main(java.lang.String[] args)
throws java.lang.Exception
args - ignoredjava.lang.Exception - if something goes wrong