|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.badlogic.gdx.utils.JsonValue
public class JsonValue
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 a for loop, either with the enhanced
for loop syntactic sugar or like the example below. This is much more efficient than accessing children by index when there are
many children.
JsonValue map = ...; for (JsonValue entry = map.child(); entry != null; entry = entry.next()) System.out.println(entry.name() + " = " + entry.asString());
Nested Class Summary | |
---|---|
class |
JsonValue.JsonIterator
|
static class |
JsonValue.ValueType
|
Field Summary | |
---|---|
JsonValue |
child
May be null. |
String |
name
|
JsonValue |
next
May be null. |
JsonValue |
prev
May be null. |
int |
size
|
Constructor Summary | |
---|---|
JsonValue(boolean value)
|
|
JsonValue(double value)
|
|
JsonValue(JsonValue.ValueType type)
|
|
JsonValue(long value)
|
|
JsonValue(String value)
|
Method Summary | |
---|---|
boolean |
asBoolean()
Returns this value as a boolean. |
double |
asDouble()
Returns this value as a double. |
float |
asFloat()
Returns this value as a float. |
int |
asInt()
Returns this value as an int. |
long |
asLong()
Returns this value as a long. |
String |
asString()
Returns this value as a string. |
JsonValue |
child()
Returns the first child for this object or array. |
JsonValue |
get(int index)
Returns the child at the specified index. |
JsonValue |
get(String name)
Returns the child with the specified name. |
boolean |
getBoolean(int index)
Finds the child with the specified index and returns it as a boolean. |
boolean |
getBoolean(String name)
Finds the child with the specified name and returns it as a boolean. |
boolean |
getBoolean(String name,
boolean defaultValue)
Finds the child with the specified name and returns it as a boolean. |
JsonValue |
getChild(String name)
Finds the child with the specified name and returns its first child. |
double |
getDouble(int index)
Finds the child with the specified index and returns it as a double. |
double |
getDouble(String name)
Finds the child with the specified name and returns it as a double. |
double |
getDouble(String name,
double defaultValue)
Finds the child with the specified name and returns it as a double. |
float |
getFloat(int index)
Finds the child with the specified index and returns it as a float. |
float |
getFloat(String name)
Finds the child with the specified name and returns it as a float. |
float |
getFloat(String name,
float defaultValue)
Finds the child with the specified name and returns it as a float. |
int |
getInt(int index)
Finds the child with the specified index and returns it as an int. |
int |
getInt(String name)
Finds the child with the specified name and returns it as an int. |
int |
getInt(String name,
int defaultValue)
Finds the child with the specified name and returns it as an int. |
long |
getLong(int index)
Finds the child with the specified index and returns it as a long. |
long |
getLong(String name)
Finds the child with the specified name and returns it as a long. |
long |
getLong(String name,
long defaultValue)
Finds the child with the specified name and returns it as a long. |
String |
getString(int index)
Finds the child with the specified index and returns it as a string. |
String |
getString(String name)
Finds the child with the specified name and returns it as a string. |
String |
getString(String name,
String defaultValue)
Finds the child with the specified name and returns it as a string. |
boolean |
hasChild(String name)
Returns true if a child with the specified name exists and has a child. |
boolean |
isArray()
|
boolean |
isBoolean()
|
boolean |
isDouble()
|
boolean |
isLong()
|
boolean |
isNull()
|
boolean |
isNumber()
Returns true if this is a double or long value. |
boolean |
isObject()
|
boolean |
isString()
|
boolean |
isValue()
Returns true if this is not an array or object. |
JsonValue.JsonIterator |
iterator()
|
String |
name()
Returns the name for this object value. |
JsonValue |
next()
Returns the next sibling of this value. |
String |
prettyPrint(JsonWriter.OutputType outputType,
int singleLineColumns)
|
JsonValue |
prev()
Returns the previous sibling of this value. |
JsonValue |
remove(int index)
Removes the child with the specified name. |
JsonValue |
remove(String name)
Removes the child with the specified name. |
JsonValue |
require(int index)
Returns the child at the specified index. |
JsonValue |
require(String name)
Returns the child with the specified name. |
void |
set(boolean value)
|
void |
set(double value)
|
void |
set(long value)
|
void |
set(String value)
|
void |
setName(String name)
|
void |
setNext(JsonValue next)
|
void |
setPrev(JsonValue prev)
|
void |
setType(JsonValue.ValueType type)
|
int |
size()
Deprecated. Use the size property instead. Returns this number of children in the array or object. |
String |
toString()
|
JsonValue.ValueType |
type()
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public String name
public JsonValue child
public JsonValue next
public JsonValue prev
public int size
Constructor Detail |
---|
public JsonValue(JsonValue.ValueType type)
public JsonValue(String value)
value
- May be null.public JsonValue(double value)
public JsonValue(long value)
public JsonValue(boolean value)
Method Detail |
---|
public JsonValue get(int index)
public JsonValue get(String name)
public JsonValue require(int index)
IllegalArgumentException
- if the child was not found.public JsonValue require(String name)
IllegalArgumentException
- if the child was not found.public JsonValue remove(int index)
public JsonValue remove(String name)
public int size()
public String asString()
IllegalStateException
- if this an array or object.public float asFloat()
IllegalStateException
- if this an array or object.public double asDouble()
IllegalStateException
- if this an array or object.public long asLong()
IllegalStateException
- if this an array or object.public int asInt()
IllegalStateException
- if this an array or object.public boolean asBoolean()
IllegalStateException
- if this an array or object.public boolean hasChild(String name)
public JsonValue getChild(String name)
public String getString(String name, String defaultValue)
defaultValue
- May be null.public float getFloat(String name, float defaultValue)
public double getDouble(String name, double defaultValue)
public long getLong(String name, long defaultValue)
public int getInt(String name, int defaultValue)
public boolean getBoolean(String name, boolean defaultValue)
public String getString(String name)
IllegalArgumentException
- if the child was not found.public float getFloat(String name)
IllegalArgumentException
- if the child was not found.public double getDouble(String name)
IllegalArgumentException
- if the child was not found.public long getLong(String name)
IllegalArgumentException
- if the child was not found.public int getInt(String name)
IllegalArgumentException
- if the child was not found.public boolean getBoolean(String name)
IllegalArgumentException
- if the child was not found.public String getString(int index)
IllegalArgumentException
- if the child was not found.public float getFloat(int index)
IllegalArgumentException
- if the child was not found.public double getDouble(int index)
IllegalArgumentException
- if the child was not found.public long getLong(int index)
IllegalArgumentException
- if the child was not found.public int getInt(int index)
IllegalArgumentException
- if the child was not found.public boolean getBoolean(int index)
IllegalArgumentException
- if the child was not found.public JsonValue.ValueType type()
public void setType(JsonValue.ValueType type)
public boolean isArray()
public boolean isObject()
public boolean isString()
public boolean isNumber()
public boolean isDouble()
public boolean isLong()
public boolean isBoolean()
public boolean isNull()
public boolean isValue()
public String name()
public void setName(String name)
public JsonValue child()
public JsonValue next()
public void setNext(JsonValue next)
public JsonValue prev()
public void setPrev(JsonValue prev)
public void set(String value)
value
- May be null.public void set(double value)
public void set(long value)
public void set(boolean value)
public String toString()
toString
in class Object
public String prettyPrint(JsonWriter.OutputType outputType, int singleLineColumns)
public JsonValue.JsonIterator iterator()
iterator
in interface Iterable<JsonValue>
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |