APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.utils

public Class JsonValue

extends Object
implements Iterable<JsonValue>
Class Inheritance
All Implemented Interfaces
java.lang.Iterable
Imports
java.io.IOException, .StringWriter, .Writer, java.util.Iterator, .NoSuchElementException, .Objects, com.badlogic.gdx.utils.JsonWriter.OutputType

Container for a JSON object, array, string, double, long, boolean, or null.

JsonValue children are a linked list. Iteration of arrays or objects is easily done using an iterator or the next() field, both shown below. This is much more efficient than accessing children by index when there are many children.

JsonValue map = ...;
// Allocates an iterator:
for (JsonValue entry : map)
	System.out.println(entry.name + " = " + entry.asString());
// No allocation:
for (JsonValue entry = map.child; entry != null; entry = entry.next)
	System.out.println(entry.name + " = " + entry.asString());
Author
Nathan Sweet

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class
public static class
public static enum

Field Summary

Modifier and TypeField and Description
public JsonValue
child

May be null.

private double
public JsonValue
last

May be null.

private long
public String
public JsonValue
next

May be null.

public JsonValue
parent

May be null.

public JsonValue
prev

May be null.

public int
private String
stringValue

May be null.

private JsonValue.ValueType

Constructor Summary

AccessConstructor and Description
public
public
JsonValue(String
May be null.
value
)

public
JsonValue(double value)

public
JsonValue(long value)

public
JsonValue(double value, String stringValue)

public
JsonValue(long value, String stringValue)

public
JsonValue(boolean value)

public
JsonValue(JsonValue value)

Creates a deep copy of the specific value, except parent(), next(), and prev() are null.

private
JsonValue(JsonValue other, JsonValue otherLast, JsonValue parent)

Method Summary

Modifier and TypeMethod and Description
public void
addChild(String name, JsonValue value)

Sets the name of the specified value and adds it after the last child.

public void
addChild(JsonValue value)

Adds the specified value after the last child.

public void
addChildFirst(JsonValue value)

Adds the specified value as the first child.

public boolean
asBoolean()

Returns this value as a boolean.

public boolean[]
asBooleanArray()

Returns the children of this value as a newly allocated boolean array.

public byte
asByte()

Returns this value as a byte.

public byte[]
asByteArray()

Returns the children of this value as a newly allocated byte array.

public char
asChar()

Returns this value as a char.

public char[]
asCharArray()

Returns the children of this value as a newly allocated char array.

public double
asDouble()

Returns this value as a double.

public double[]
asDoubleArray()

Returns the children of this value as a newly allocated double array.

public float
asFloat()

Returns this value as a float.

public float[]
asFloatArray()

Returns the children of this value as a newly allocated float array.

public int
asInt()

Returns this value as an int.

public int[]
asIntArray()

Returns the children of this value as a newly allocated int array.

public long
asLong()

Returns this value as a long.

public long[]
asLongArray()

Returns the children of this value as a newly allocated long array.

public short
asShort()

Returns this value as a short.

public short[]
asShortArray()

Returns the children of this value as a newly allocated short array.

public String

Returns:

May be null if this value is null.
asString
()

Returns this value as a string.

public String[]
asStringArray()

Returns the children of this value as a newly allocated String array.

public JsonValue

Returns:

May be null.
child
()

Returns the first child for this object or array.

public boolean
public JsonValue

Returns:

May be null.
get
(int index)

Returns the child at the specified index.

public JsonValue

Returns:

May be null.
get
(String name)

Returns the child with the specified name.

public boolean
getBoolean(String name, boolean defaultValue)

Finds the child with the specified name and returns it as a boolean.

public boolean
getBoolean(String name)

Finds the child with the specified name and returns it as a boolean.

public boolean
getBoolean(int index)

Finds the child with the specified index and returns it as a boolean.

public byte
getByte(String name, byte defaultValue)

Finds the child with the specified name and returns it as a byte.

public byte
getByte(String name)

Finds the child with the specified name and returns it as a byte.

public byte
getByte(int index)

Finds the child with the specified index and returns it as a byte.

public char
getChar(String name, char defaultValue)

Finds the child with the specified name and returns it as a char.

public char
getChar(String name)

Finds the child with the specified name and returns it as a char.

public char
getChar(int index)

Finds the child with the specified index and returns it as a char.

public JsonValue

Returns:

May be null.
getChild
(String name)

Finds the child with the specified name and returns its first child.

public double
getDouble(String name, double defaultValue)

Finds the child with the specified name and returns it as a double.

public double
getDouble(String name)

Finds the child with the specified name and returns it as a double.

public double
getDouble(int index)

Finds the child with the specified index and returns it as a double.

public float
getFloat(String name, float defaultValue)

Finds the child with the specified name and returns it as a float.

public float
getFloat(String name)

Finds the child with the specified name and returns it as a float.

public float
getFloat(int index)

Finds the child with the specified index and returns it as a float.

public JsonValue

Returns:

May be null.
getIgnoreCase
(String name)

Returns the child with the specified name, ignoring case.

public int
getInt(String name, int defaultValue)

Finds the child with the specified name and returns it as an int.

public int
getInt(String name)

Finds the child with the specified name and returns it as an int.

public int
getInt(int index)

Finds the child with the specified index and returns it as an int.

public long
getLong(String name, long defaultValue)

Finds the child with the specified name and returns it as a long.

public long
getLong(String name)

Finds the child with the specified name and returns it as a long.

public long
getLong(int index)

Finds the child with the specified index and returns it as a long.

public short
getShort(String name, short defaultValue)

Finds the child with the specified name and returns it as a short.

public short
getShort(String name)

Finds the child with the specified name and returns it as a short.

public short
getShort(int index)

Finds the child with the specified index and returns it as a short.

public String
getString(String name, String
May be null.
defaultValue
)

Finds the child with the specified name and returns it as a string.

public String
getString(String name)

Finds the child with the specified name and returns it as a string.

public String
getString(int index)

Finds the child with the specified index and returns it as a string.

public boolean
has(String name)

Returns true if a child with the specified name exists.

public boolean
hasChild(String name)

Returns true if a child with the specified name exists and has a child.

private static void
indent(int count, StringBuilder buffer)

private static void
indent(int count, Writer writer)

public boolean
public boolean
public boolean
public boolean
isEmpty()

Returns true if there are not children in the array or object.

private static boolean
isFlat(JsonValue object)

public boolean
public boolean
public boolean
isNumber()

Returns true if this is a double or long value.

private static boolean
public boolean
public boolean
public boolean
isValue()

Returns true if this is not an array or object.

public JsonValue.JsonIterator
iterator(String name)

Returns an iterator for the child with the specified name, or an empty iterator if no child is found.

public JsonValue.JsonIterator
iterator()

Implements java.lang.Iterable.iterator.

Iterates the children of this array or object.

public JsonValue

Returns:

May be null.
last
()

Returns the last child for this object or array.

public String

Returns:

May be null.
name
()

Returns the name for this object value.

public boolean
public JsonValue

Returns:

May be null.
next
()

Returns the next sibling of this value.

public boolean
notEmpty()

Returns true if there are one or more children in the array or object.

public JsonValue

Returns:

May be null.
parent
()

Returns the parent for this value.

public String
prettyPrint(JsonWriter.OutputType outputType, int singleLineColumns)

public String
private void
prettyPrint(JsonValue object, StringBuilder buffer, int indent, JsonValue.PrettyPrintSettings settings)

public void
private void
prettyPrint(JsonValue object, Writer writer, int indent, JsonValue.PrettyPrintSettings settings)

public JsonValue

Returns:

May be null.
prev
()

Returns the previous sibling of this value.

public JsonValue

Returns:

May be null.
remove
(int index)

Removes the child with the specified index.

public JsonValue

Returns:

May be null.
remove
(String name)

Removes the child with the specified name.

public void
remove()

Removes this value from its parent.

public void
replace(JsonValue value)

Replaces this value in its parent with the specified value.

public JsonValue
require(int index)

Returns the child at the specified index.

public JsonValue
require(String name)

Returns the child with the specified name.

public void
set(JsonValue value)

Sets the type and value to the specified JsonValue.

public void
set(String
May be null.
value
)

public void
set(double value, String
May be null if the string representation is the string value of the double (eg, no leading zeros).
stringValue
)

public void
set(long value, String
May be null if the string representation is the string value of the long (eg, no leading zeros).
stringValue
)

public void
set(boolean value)

public void
setChild(String name, JsonValue value)

Sets the name of the specified value and replaces an existing child with the same name, else adds it after the last child.

public void
setChild(JsonValue value)

Replaces an existing child with the same name as the specified value, else adds it after the last child.

public void
setName(String
May be null.
name
)

public void
setNext(JsonValue
May be null.
next
)

Sets the next sibling of this value.

public void
public void
setPrev(JsonValue
May be null.
prev
)

Sets the next sibling of this value.

public void
public int
size()
Deprecated Use size instead. Returns this number of children in the array or object.

public String
public void
toJson(JsonWriter.OutputType outputType, Writer writer)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public String
trace()

Returns a human readable string representing the path from the root of the JSON object graph to this value.

public JsonValue.ValueType
type()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait