JsonParserGeneratorRK
Public Member Functions
JsonReference Class Reference

This class provides a fluent-style API for easily traversing a tree of JSON objects to find a value. More...

#include <JsonParserGeneratorRK.h>

Public Member Functions

 JsonReference (const JsonParser *parser)
 Constructs an object. Normally you use the JsonParser getReference() method to get one of these instead of constructing one. More...
 
virtual ~JsonReference ()
 Destructor. This does not affect the lifecycle of the JsonParser.
 
 JsonReference (const JsonParser *parser, const JsonParserGeneratorRK::jsmntok_t *token)
 Constructs are JsonReference for a specific token within a JsonParser.
 
JsonReference key (const char *name) const
 For JsonReference that refers to a JSON object, gets a new JsonReference to a value with the specified key name. More...
 
JsonReference index (size_t index) const
 For a JsonReference that refers to a JSON array, gets a new JsonReference to a value in the array by index. More...
 
size_t size () const
 For a JsonReference that refers to a JSON array, gets the size of the array. More...
 
template<class T >
bool value (T &result) const
 Get a value of the specified type for a given value for a specified key, or index for an array. More...
 
bool valueBool (bool defaultValue=false) const
 Returns a boolean (bool) value for an object value for key, or array index. More...
 
int valueInt (int defaultValue=0) const
 Returns a integer (int) value for an object value for key, or array index. More...
 
unsigned long valueUnsignedLong (unsigned long defaultValue=0) const
 Returns a unsigned long integer for an object value for key, or array index. More...
 
float valueFloat (float defaultValue=0.0) const
 Returns a float value for an object value for key, or array index. More...
 
double valueDouble (double defaultValue=0.0) const
 Returns a double value for an object value for key, or array index. More...
 
String valueString () const
 Returns a String value for an object value for key, or array index. More...
 

Detailed Description

This class provides a fluent-style API for easily traversing a tree of JSON objects to find a value.

Constructor & Destructor Documentation

◆ JsonReference()

JsonReference::JsonReference ( const JsonParser *  parser)

Constructs an object. Normally you use the JsonParser getReference() method to get one of these instead of constructing one.

Parameters
parserThe JsonParser object you're traversing

Member Function Documentation

◆ index()

JsonReference JsonReference::index ( size_t  index) const

For a JsonReference that refers to a JSON array, gets a new JsonReference to a value in the array by index.

Parameters
indexThe index to retrieve (0 = first item, 1 = second item, ...).
Returns
A JsonReference to the value for this index.

◆ key()

JsonReference JsonReference::key ( const char *  name) const

For JsonReference that refers to a JSON object, gets a new JsonReference to a value with the specified key name.

Parameters
nameof the key to look for.
Returns
A JsonReference to the value for this key.

◆ size()

size_t JsonReference::size ( ) const

For a JsonReference that refers to a JSON array, gets the size of the array.

Returns
0 = an empty array, 1 = one element, ...

◆ value()

template<class T >
bool JsonReference::value ( T &  result) const
inline

Get a value of the specified type for a given value for a specified key, or index for an array.

Parameters
resultFilled in with the value. The value can be of type: bool, int, unsigned long, float, double, String, or (char *, size_t&).

There are also type-specific versions like valueBool that return the value, instead of having to pass an object to hold the value, as in this call.

◆ valueBool()

bool JsonReference::valueBool ( bool  defaultValue = false) const

Returns a boolean (bool) value for an object value for key, or array index.

Parameters
defaultValueOptional value to use if the key or array index is not found. Default: false.

◆ valueDouble()

double JsonReference::valueDouble ( double  defaultValue = 0.0) const

Returns a double value for an object value for key, or array index.

Parameters
defaultValueOptional value to use if the key or array index is not found. Default: 0.0.

◆ valueFloat()

float JsonReference::valueFloat ( float  defaultValue = 0.0) const

Returns a float value for an object value for key, or array index.

Parameters
defaultValueOptional value to use if the key or array index is not found. Default: 0.0.

◆ valueInt()

int JsonReference::valueInt ( int  defaultValue = 0) const

Returns a integer (int) value for an object value for key, or array index.

Parameters
defaultValueOptional value to use if the key or array index is not found. Default: 0.

◆ valueString()

String JsonReference::valueString ( ) const

Returns a String value for an object value for key, or array index.

Returns
The string value, or an empty string if the key or array index is not found.

◆ valueUnsignedLong()

unsigned long JsonReference::valueUnsignedLong ( unsigned long  defaultValue = 0) const

Returns a unsigned long integer for an object value for key, or array index.

Parameters
defaultValueOptional value to use if the key or array index is not found. Default: 0.

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