NetBurner 3.5.0
PDF Version
 
JsonRef Class Reference

Represents a positional reference (pointer) of a location inside a ParsedJsonDataSet object
More...

#include <json_lexer.h>

Public Member Functions

Querying the Data Structure

Allows easy retrieval of entities by array index or object key name

Example
printf("User %d name %s",
(int)myJsonRef("users")[0]("id"),
(const char *)myJsonRef("users")[0]("name")
);
JsonRef operator[] (int i)
 Get a JsonRef from an array by numerical index.
 
JsonRef object (const char *name)
 Get a JsonRef representing an object from a parent object by key name.
 
JsonRef name (const char *name)
 Get a JsonRef representing any entity from a parent object by key name.
 
JsonRef operator() (const char *namev)
 Get a JsonRef representing any entity from a parent object by key name.
 
Types and Operators

Allows casting of a JsonRef to the desired type

Example
bool b = (bool)myJsonRef("user")("isEnabled");
int i = (int)myJsonRef("user")("id");
const char *str = (const char *)myJsonRef("user")("name");
 operator bool () const
 Operator to return a JSON element of type boolean.
 
 operator float () const
 Operator to return a JSON element of type float.
 
 operator double () const
 Operator to return a JSON element of type double.
 
 operator uint8_t () const
 Operator to return a JSON element of type uint8_t.
 
 operator int () const
 Operator to return a JSON element of type int.
 
 operator uint16_t () const
 Operator to return a JSON element of type uint16_t.
 
 operator uint32_t () const
 Operator to return a JSON element of type uint32_t.
 
 operator int8_t () const
 Operator to return a JSON element of type int8_t.
 
 operator int16_t () const
 Operator to return a JSON element of type int16_t.
 
 operator int32_t () const
 Operator to return a JSON element of type int32_t.
 
 operator time_t () const
 Operator to return a JSON element of type time_t.
 
 operator const char * () const
 Operator to return a JSON element of type const char *.
 
 operator NBString () const
 Operator to return a JSON element of type NBString.
 
Checking Validity
bool IsNumber ()
 Check if the current JsonRef is a valid JSON number element.
 
bool IsObject ()
 Check if the current JsonRef is a valid JSON object element.
 
bool IsString ()
 Check if the current JsonRef is a valid JSON string element.
 
bool IsBool ()
 Check if the current JsonRef is a valid JSON boolean element.
 
bool IsNull ()
 Check if the current JsonRef is a valid JSON null element.
 
bool IsArray ()
 Check if the current JsonRef is a valid JSON array element.
 
bool Valid () const
 Check if the current JsonRef is a valid JSON position.
 
Traversing the Data Structure
JsonRef start ()
 Begin traversal: check for ref validity and reset the position.
 
JsonRef next () const
 Traverse: check for ref validity and increment the position.
 
bool IncPosition ()
 Increment the position index of the ParsedJsonDataSet.
 
bool JumpPosition (int siz)
 Jump to a specific position index in the ParsedJsonDataSet.
 
void ResetPosition ()
 Reset the position index of the ParsedJsonDataSet to the beginning.
 
void SkipElement ()
 Increment the position index of the ParsedJsonDataSet beyond this element.
 
void SkipArray ()
 Increment the position index of the ParsedJsonDataSet beyond this array.
 
void SkipObject ()
 Increment the position index of the ParsedJsonDataSet beyond this object.
 
Utility
int PrintChildren (bool pretty=false)
 Output child objects of this JsonRef as JSON text to stdout.
 
int PrintChildrenToFd (int fd, bool pretty=false)
 Output child objects of this JsonRef as JSON text to a file descriptor.
 
int PrintChildrenToBuffer (char *buffer, int maxlen, bool pretty=false)
 Output child objects of this JsonRef as JSON text to a buffer pointer.
 
int PrintChildrenToString (NBString &s, bool pretty=false)
 Output child objects of this JsonRef as JSON text to a NBString.
 
int GetChildPrintSize (bool pretty=false)
 Return the length of the child objects' JSON text as written with the PrintChildren* functions.
 
void DiagDump (const char *lab)
 Output a verbose diagnostic report of the ParsedJsonDatSet to stdout.
 
void MakeInvalid ()
 

Friends

class ParsedJsonDataSet
 

Detailed Description

Represents a positional reference (pointer) of a location inside a ParsedJsonDataSet object

A JsonRef can be used as a pointer to a variable or sub object inside a ParsedJsonDataSet object to make decoding the hierarchy much simpler and easier to understand. A JsonRef is not limited to just pointing at internal objects; it can point to any JSON parsed token/type.

Member Function Documentation

◆ GetChildPrintSize()

int JsonRef::GetChildPrintSize ( bool pretty = false)

Return the length of the child objects' JSON text as written with the PrintChildren* functions.

Parameters
prettyWhether indentation and new lines should be provided between elements.
Returns
The number of characters needed to print the JSON data set.

◆ IsArray()

bool JsonRef::IsArray ( )
inline

Check if the current JsonRef is a valid JSON array element.

Returns
True if parsed JSON element is an array, otherwise false.

◆ IsBool()

bool JsonRef::IsBool ( )
inline

Check if the current JsonRef is a valid JSON boolean element.

Returns
True if parsed JSON element is a boolean, otherwise false.

◆ IsNull()

bool JsonRef::IsNull ( )
inline

Check if the current JsonRef is a valid JSON null element.

Returns
True if parsed JSON element is a null, otherwise false.

◆ IsNumber()

bool JsonRef::IsNumber ( )
inline

Check if the current JsonRef is a valid JSON number element.

Returns
True if parsed JSON element is a number, otherwise false.

◆ IsObject()

bool JsonRef::IsObject ( )
inline

Check if the current JsonRef is a valid JSON object element.

Returns
True if parsed JSON element is an object, otherwise false.

◆ IsString()

bool JsonRef::IsString ( )
inline

Check if the current JsonRef is a valid JSON string element.

Returns
True if parsed JSON element is a string, otherwise false. A string can be of type char *, or a NBString object.

◆ MakeInvalid()

void JsonRef::MakeInvalid ( )
inline

◆ name()

JsonRef JsonRef::name ( const char * name)

Get a JsonRef representing any entity from a parent object by key name.

Useful if more than one JSON object/element has the same name.

Example
JsonRef userThree = myJsonRef.name("users")[3];
Represents a positional reference (pointer) of a location inside a ParsedJsonDataSet object
Definition json_lexer.h:112
JsonRef name(const char *name)
Get a JsonRef representing any entity from a parent object by key name.
Parameters
*namePointer to name of the entity to find
Returns
The reference to the entity of type JsonRef
See also
JsonRef::operator()(), JsonRef::object()

◆ object()

JsonRef JsonRef::object ( const char * name)
inline

Get a JsonRef representing an object from a parent object by key name.

Example
JsonRef john = myJsonRef.object("users").object("john");
JsonRef object(const char *name)
Get a JsonRef representing an object from a parent object by key name.
Definition json_lexer.h:183
Parameters
*namePointer to name of the object to find
Returns
The reference to the object of type JsonRef

◆ operator bool()

JsonRef::operator bool ( ) const
inline

Operator to return a JSON element of type boolean.

Returns
Boolean value

◆ operator const char *()

JsonRef::operator const char * ( ) const
inline

Operator to return a JSON element of type const char *.

Returns
const char * value

◆ operator double()

JsonRef::operator double ( ) const
inline

Operator to return a JSON element of type double.

Returns
double value

◆ operator float()

JsonRef::operator float ( ) const
inline

Operator to return a JSON element of type float.

Returns
float value

◆ operator int()

JsonRef::operator int ( ) const
inline

Operator to return a JSON element of type int.

Returns
integer value

◆ operator int16_t()

JsonRef::operator int16_t ( ) const
inline

Operator to return a JSON element of type int16_t.

Returns
int16_t value

◆ operator int32_t()

JsonRef::operator int32_t ( ) const
inline

Operator to return a JSON element of type int32_t.

Returns
int32_t value

◆ operator int8_t()

JsonRef::operator int8_t ( ) const
inline

Operator to return a JSON element of type int8_t.

Returns
int8_t value

◆ operator NBString()

JsonRef::operator NBString ( ) const
inline

Operator to return a JSON element of type NBString.

Returns
NBString object

◆ operator time_t()

JsonRef::operator time_t ( ) const
inline

Operator to return a JSON element of type time_t.

Returns
time_t value

◆ operator uint16_t()

JsonRef::operator uint16_t ( ) const
inline

Operator to return a JSON element of type uint16_t.

Returns
uint16_t value

◆ operator uint32_t()

JsonRef::operator uint32_t ( ) const
inline

Operator to return a JSON element of type uint32_t.

Returns
uint32_t value

◆ operator uint8_t()

JsonRef::operator uint8_t ( ) const
inline

Operator to return a JSON element of type uint8_t.

Returns
uint8_t value

◆ operator()()

JsonRef JsonRef::operator() ( const char * namev)
inline

Get a JsonRef representing any entity from a parent object by key name.

Shortcut for JsonRef::name()

Example
JsonRef allUsers = myJsonRef("users");
Parameters
*namevPointer to name of the entity to find
Returns
The reference to the entity of type JsonRef
See also
JsonRef::name(), JsonRef::object()

◆ operator[]()

JsonRef JsonRef::operator[] ( int i)

Get a JsonRef from an array by numerical index.

Example
JsonRef userThree = myJsonRef("users")[3];
Returns
A JsonRef if array element is found

◆ Valid()

bool JsonRef::Valid ( ) const
inline

Check if the current JsonRef is a valid JSON position.

Returns
True if a JSON element exists, otherwise false.

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