Voffcon NodeMcu device server
 All Classes Functions
JsonData Class Reference

Class for representing elements and objects in a json object. You can use it to browse and get values and add and remove objects from a json. More...

Public Member Functions

 JsonData (const char *jsonString)
 Parses the json_string into a new JsonData object More...
 
 ~JsonData ()
 Deconstruct-or for the JsonData object Will remove the object and it's children from memory More...
 
String toString ()
 Returns the object as a JSON string. This string should be a valid JSON string, ready to be sent over the wire. More...
 
String toTree ()
 Prints the object as a tree More...
 
bool isValid () const
 Will tell you if the current object is invalid More...
 
bool hasChildren ()
 Checks if the current object has any child objects More...
 
JsonDatagetChildAt (unsigned int index)
 Gets a a pointer to a child at a specific index. If no child is found at given location NULL is returned More...
 
JsonDatagetChild (String value)
 Searches for a child with a specific value. Good for searching for a spesific JSONTYPE_KEY_VALUE f.example More...
 
JsonDatagetNext ()
 Gets a a pointer to the next sibling of this object. This function does NEVER return a child object. If no sibling is found NULL is returned More...
 
const String getValue ()
 Gets the value of an object. If the object is a JSONTYPE_KEY_VALUE then the child object value is NOT returned. More...
 
String getValueAsString ()
 Returns the value of an object as a String. If the object is a JSONTYPE_KEY_VALUE then the child object value is returned as a String More...
 
float getValueAsFloat ()
 Converts the value of an object from string to a float. If the object is a JSONTYPE_KEY_VALUE then the child object value is returned as a number More...
 
unsigned long getValueAsULong ()
 Converts the value of an object from string to a unsigned long. Note the type of the value must be a positive number (JSONTYPE_ULONG). If the object is a JSONTYPE_KEY_VALUE then the child object value is returned as a number More...
 
long getValueAsLong ()
 Converts the value of an object from string to a long number. If the object is a JSONTYPE_KEY_VALUE then the child object value is returned as a number More...
 
int getValueAsInt ()
 Converts the value of an object from string to a integer number. If the object is a JSONTYPE_KEY_VALUE then the child object value is returned as a number More...
 
JSONTYPE getType () const
 
JSONTYPE getValueType () const
 

Static Public Member Functions

static String trim (String jsonStringToTrim)
 Will remove all white space characters from a string. The function will not touch sections of a string within quotation marks. Comments will also be removed from the json object More...
 

Detailed Description

Class for representing elements and objects in a json object. You can use it to browse and get values and add and remove objects from a json.

Example hello World:

1 // Create an json object with one key named "hello"
2 // and one value which is the string "world"
3 JsonData js("{\"hello\":\"world\"}");

Constructor & Destructor Documentation

JsonData::JsonData ( const char *  jsonString)

Parses the json_string into a new JsonData object

Example one:

1 // Create an empty json object
2 JsonData jsEmptyObject("{}");

Example two:

1 // Create an empty json array
2 JsonData jsEmptyArray("[]");
Parameters
jsonStringMust be a valid JSON string
JsonData::~JsonData ( )

Deconstruct-or for the JsonData object Will remove the object and it's children from memory

Member Function Documentation

JsonData * JsonData::getChild ( String  value)

Searches for a child with a specific value. Good for searching for a spesific JSONTYPE_KEY_VALUE f.example

Parameters
valueValue to search for. the search is case sensitive
Returns
Pointer to the object. If no object is found NULL is returned
JsonData * JsonData::getChildAt ( unsigned int  index)

Gets a a pointer to a child at a specific index. If no child is found at given location NULL is returned

Parameters
indexZero based index of the child to get
Returns
Pointer to the object. If no object is found NULL is returned
JsonData * JsonData::getNext ( )

Gets a a pointer to the next sibling of this object. This function does NEVER return a child object. If no sibling is found NULL is returned

Returns
Pointer to the next sibling. If no sibling exists, NULL is returned.
const String JsonData::getValue ( )

Gets the value of an object. If the object is a JSONTYPE_KEY_VALUE then the child object value is NOT returned.

Returns
The value as a string
float JsonData::getValueAsFloat ( )

Converts the value of an object from string to a float. If the object is a JSONTYPE_KEY_VALUE then the child object value is returned as a number

Returns
Success: If no valid conversion could be performed because the String doesn’t start with a digit, a zero is returned. Data type: float. Fail: the number 999999999
int JsonData::getValueAsInt ( )

Converts the value of an object from string to a integer number. If the object is a JSONTYPE_KEY_VALUE then the child object value is returned as a number

Returns
Succsess: A integer number. Fail: 999999999
long JsonData::getValueAsLong ( )

Converts the value of an object from string to a long number. If the object is a JSONTYPE_KEY_VALUE then the child object value is returned as a number

Returns
Succsess: A long number. Fail: 999999999
String JsonData::getValueAsString ( )

Returns the value of an object as a String. If the object is a JSONTYPE_KEY_VALUE then the child object value is returned as a String

Returns
The values as a String
unsigned long JsonData::getValueAsULong ( )

Converts the value of an object from string to a unsigned long. Note the type of the value must be a positive number (JSONTYPE_ULONG). If the object is a JSONTYPE_KEY_VALUE then the child object value is returned as a number

Returns
Succsess: A unsinged long number. Fail: 999999999
bool JsonData::hasChildren ( )
inline

Checks if the current object has any child objects

Returns
true if this object has one ore more child object(s). Otherwize false
bool JsonData::isValid ( ) const

Will tell you if the current object is invalid

String JsonData::toString ( )

Returns the object as a JSON string. This string should be a valid JSON string, ready to be sent over the wire.

Returns
The current object returned as an JSON String.
String JsonData::toTree ( )

Prints the object as a tree

Returns
A string ready to be sent to the console
String JsonData::trim ( String  jsonStringToTrim)
static

Will remove all white space characters from a string. The function will not touch sections of a string within quotation marks. Comments will also be removed from the json object

Parameters
jsonStringToTrimThe string to remove whitespaces from
Returns
A string without white spaces

The documentation for this class was generated from the following file: