|
C++ TargetRTS
|
Represents the result of parsing a JSON string. More...
#include <RTJsonResult.h>
Public Types | |
| enum | RTJsonType { RTJSON_NULL , RTJSON_OBJ , RTJSON_ARR , RTJSON_STR , RTJSON_NUM , RTJSON_BOOL } |
| The type of JSON value represented by the RTJsonResult object. More... | |
Public Member Functions | |
| const RTJsonResult & | operator[] (const std::string &key) const |
| For a JSON object, return the value for the key with the given name. | |
| const RTJsonResult & | operator[] (size_t index) const |
| For a JSON array, return the value at the given index. | |
| size_t | get_size () const |
| For a JSON array, return the number of array elements. | |
| std::map< std::string, RTJsonResult >::const_iterator | keys_begin () const |
| For a JSON object, return its keys begin iterator. | |
| std::map< std::string, RTJsonResult >::const_iterator | keys_end () const |
| For a JSON object, return its keys end iterator. | |
| RTJsonResult & | operator= (const RTJsonResult &other) |
| Assignment operator. | |
| RTJsonResult (const RTJsonResult &other) | |
| Copy constructor. | |
| bool | ok () const |
| Returns false if this object represents an error result, true otherwise. | |
| const std::string & | get_string () const |
| Get a string representation of the JSON value. | |
| RTJsonType | get_type () const |
| Get the type of JSON value represented by the RTJsonResult. | |
| bool | get_bool () const |
| Interpret the JSON value as a bool. | |
| int | get_int () const |
| Interpret the JSON value as an int. | |
| float | get_float () const |
| Interpret the JSON value as a float. | |
| double | get_double () const |
| Interpret the JSON value as a double. | |
| bool | operator== (const RTJsonResult &) const |
| Determines if the JSON value is equal (but not necessarily the same) as another JSON value. | |
| bool | operator== (const bool) const |
| Determines if the JSON value is boolean and equal to the given bool. | |
| bool | operator== (const int) const |
| Determines if the JSON value is numeric and equal to the given int. | |
| bool | operator== (const float) const |
| Determines if the JSON value is numeric and equal to the given float. | |
| bool | operator== (const double) const |
| Determines if the JSON value is numeric and equal to the given double. | |
| bool | operator== (const char *) const |
| Determines if the JSON value is a string and equal to the given string. | |
Static Public Attributes | |
| static const RTJsonResult | ERROR |
| This special object represents an error result. | |
Friends | |
| class | RTJsonParser |
| class | RTJsonParserUtils |
Represents the result of parsing a JSON string.
The result from parsing is a tree of RTJsonResult objects where the root is representing a JSON object or array. Leaf objects of the tree are RTJsonResult objects that represent JSON values.
The type of JSON value represented by the RTJsonResult object.
| Enumerator | |
|---|---|
| RTJSON_NULL | The special null value. |
| RTJSON_OBJ | JSON object value. |
| RTJSON_ARR | JSON array value. |
| RTJSON_STR | JSON string value. |
| RTJSON_NUM | JSON numeric value. |
| RTJSON_BOOL | JSON boolean value. |
| bool RTJsonResult::get_bool | ( | ) | const |
Interpret the JSON value as a bool.
Only call this for JSON boolean values.
| double RTJsonResult::get_double | ( | ) | const |
Interpret the JSON value as a double.
Only call this for JSON numeric values.
| float RTJsonResult::get_float | ( | ) | const |
Interpret the JSON value as a float.
Only call this for JSON numeric values.
| int RTJsonResult::get_int | ( | ) | const |
Interpret the JSON value as an int.
Only call this for JSON numeric values.
| size_t RTJsonResult::get_size | ( | ) | const |
For a JSON array, return the number of array elements.
For a JSON object, return the number of keys. For other JSON values, return 0.
| const std::string & RTJsonResult::get_string | ( | ) | const |
Get a string representation of the JSON value.
Note that all values have a string representation except arrays and objects for which an empty string is returned.
| const RTJsonResult & RTJsonResult::operator[] | ( | const std::string & | key | ) | const |
For a JSON object, return the value for the key with the given name.
If the RTJsonResult does not represent a JSON object, or a key with the specified name does not exist, the ERROR result is returned.
| [in] | object | key name |
| const RTJsonResult & RTJsonResult::operator[] | ( | size_t | index | ) | const |
For a JSON array, return the value at the given index.
For a JSON object, return the value for the key at the given index. Since the order of keys is not significant in JSON it's not recommended to call this function for a JSON object. In other cases the ERROR result is returned.
| [in] | index | of value to obtain |