public class JSON
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
typArray |
static int |
typBool |
static int |
typInvalid |
static int |
typNull |
static int |
typNumber |
static int |
typRef |
static int |
typString |
Constructor and Description |
---|
JSON() |
Modifier and Type | Method and Description |
---|---|
JSONObject |
add(java.lang.String name,
boolean value) |
JSONObject |
add(java.lang.String name,
double value) |
JSONObject |
add(java.lang.String name,
int value) |
JSONObject |
add(java.lang.String name,
JSON value) |
JSONObject |
add(java.lang.String name,
java.lang.String value) |
JSON |
addBool(java.lang.String s,
boolean val)
Add a child of type boolean.
|
JSON |
addDouble(java.lang.String s,
double val)
Add a child of type double.
|
JSON |
addInt(java.lang.String s,
int val)
Add a child of type int.
|
JSON |
addItem(java.lang.String s,
JSON js)
Add a child of type JSON (en existing node).
|
JSON |
addString(java.lang.String s,
java.lang.String val)
Add a child of type String.
|
static JSONArray |
createArray(boolean[] arr) |
static JSONArray |
createArray(double[] arr) |
static JSONArray |
createArray(int[] arr) |
static JSONArray |
createArray(JSON[] arr) |
static JSON |
createBoolArray(boolean[] val)
Creates a JSON array from the given value.
|
static JSON |
createDoubleArray(double[] val)
Creates a JSON array from the given value.
|
static JSON |
createIntArray(int[] val)
Creates a JSON array from the given value.
|
static JSON |
createStringArray(java.lang.String[] val)
Creates a JSON array from the given value.
|
void |
deleteItemFromArray(int index)
Delete an item in JSON object
|
void |
deleteItemFromObject(java.lang.String key)
Delete an item in JSON object
|
JSON |
detachItemFromArray(int index)
Detach an item from JSON array
|
JSON |
detachItemFromObject(java.lang.String key)
Detach an item from JSON object
|
JSON |
getArrayItem(int index)
Returns the array item as a new JSON object.
|
JSON |
getObjectItem(java.lang.String name)
looks for an item with the specified name
|
int |
getSize()
Checks if the item is an array and returns its size
|
int |
getType() |
boolean |
getValueBool()
Checks if the item is a boolean and returns its value
|
double |
getValueDouble()
Checks if the item is a double integer and returns its valueDouble
|
int |
getValueInt()
Checks if the item is a number and returns its valueInt
|
java.lang.String |
getValueStr()
Checks if the item is a string and returns its valueString
|
static JSON |
parse(byte[] buf)
Parses the given buffer (for example retrieved from an MQTT message) into a JSON object.
|
static JSON |
parse(java.lang.String str)
Parses the given string (for example retrieved from an MQTT message) into a JSON object.
|
java.lang.String |
serialize()
Serializes the JSON object to a String, for instance to be sent over MQTT.
|
java.lang.String |
serializeMinify()
Serializes the JSON object to a String, for instance, to be sent over MQTT.
|
public static final int typInvalid
public static final int typNull
public static final int typBool
public static final int typNumber
public static final int typString
public static final int typArray
public static final int typRef
public int getType()
public JSON getObjectItem(java.lang.String name)
name
- public java.lang.String getValueStr()
public int getValueInt()
public double getValueDouble()
public boolean getValueBool()
public java.lang.String serialize()
public java.lang.String serializeMinify()
public static JSON parse(java.lang.String str)
str
- the string to parsepublic static JSON parse(byte[] buf)
buf
- the buffer to parsepublic JSON addItem(java.lang.String s, JSON js)
s
- is the name of the new fieldjs
- is the reference to the existing nodepublic JSON addString(java.lang.String s, java.lang.String val)
s
- is the name of the new fieldval
- is the vlue of the number (String).public JSON addInt(java.lang.String s, int val)
s
- is the name of the new fieldval
- is the vlue of the number (int).public JSON addBool(java.lang.String s, boolean val)
s
- is the name of the new fieldval
- is the vlue of the number (boolean).public JSON addDouble(java.lang.String s, double val)
s
- is the name of the new fieldval
- is the vlue of the number (double).public JSON detachItemFromObject(java.lang.String key)
key
- is object keypublic JSON detachItemFromArray(int index)
key
- is index arraypublic void deleteItemFromObject(java.lang.String key)
key
- is object keypublic void deleteItemFromArray(int index)
key
- is object keypublic static JSON createDoubleArray(double[] val)
val
- public static JSON createIntArray(int[] val)
val
- public static JSON createStringArray(java.lang.String[] val)
val
- public static JSON createBoolArray(boolean[] val)
val
- public int getSize()
public JSON getArrayItem(int index)
index
- public static JSONArray createArray(int[] arr)
public static JSONArray createArray(double[] arr)
public static JSONArray createArray(boolean[] arr)
public JSONObject add(java.lang.String name, java.lang.String value)
public JSONObject add(java.lang.String name, int value)
public JSONObject add(java.lang.String name, double value)
public JSONObject add(java.lang.String name, boolean value)
public JSONObject add(java.lang.String name, JSON value)