|
10Duke Enterprise C++ Client
|
JSON support.
Interfaces for simple JSON support.
Namespaces | |
| namespace | cjson |
Implementation of JSON service interfaces using cJSON. | |
Classes | |
| class | JSONArray |
| A JSON array. More... | |
| class | JSONArrayBuilder |
| Builds JSON-array. More... | |
| class | JSONBoolean |
| JSON boolean. More... | |
| class | JSONBuilder |
| NOTE: This class is for now INTERNAL USE ONLY. More... | |
| class | JSONElement |
| Superclass of JSON elements. More... | |
| class | JSONException |
| Thrown on JSON-related errors. More... | |
| class | JSONNumber |
| Represents JSON number. More... | |
| class | JSONObject |
| JSON object element. More... | |
| class | JSONObjectBuilder |
| Builds JSON objects. More... | |
| class | JSONParser |
| Parser for JSON documents. More... | |
| class | JSONParsingException |
| Thrown when JSON parsing failed. More... | |
| class | JSONString |
| JSON string element. More... | |
Functions | |
| tenduke::json::JSONArray * | castToArray (tenduke::json::JSONElement *element) |
| Type-casts given element to JSONArray. | |
| tenduke::json::JSONArray * | castToArray (const std::shared_ptr< tenduke::json::JSONElement > &element) |
| Type-casts given element to JSONArray. | |
| tenduke::json::JSONArray * | castToArray (const std::unique_ptr< tenduke::json::JSONElement > &element) |
| Type-casts given element to JSONArray. | |
| tenduke::json::JSONObject * | castToObject (tenduke::json::JSONElement *element) |
| Type-casts given element to JSONObject. | |
| tenduke::json::JSONObject * | castToObject (const std::shared_ptr< tenduke::json::JSONElement > &element) |
| Type-casts given element to JSONObject. | |
| tenduke::json::JSONObject * | castToObject (const std::unique_ptr< tenduke::json::JSONElement > &element) |
| Type-casts given element to JSONObject. | |
| std::int64_t | toInt64 (const JSONElement *element, bool throwIfInvalid=true, std::int64_t defaultValue=0) |
Returns given element as std::int_64t, assuming the element is JSONNumber. | |
| std::int64_t | toInt64 (const JSONElement &element, bool throwIfInvalid=true, std::int64_t defaultValue=0) |
Returns given element as std::int_64t, assuming the element is JSONNumber. | |
| bool | isBooleanTrue (const JSONElement *element) |
Returns true if element is JSONBoolean with value true. | |
| bool | isBooleanTrue (const std::unique_ptr< const JSONElement > &element) |
Returns true if element is JSONBoolean with value true. | |
| bool | isBooleanTrue (const std::shared_ptr< const JSONElement > &element) |
Returns true if element is JSONBoolean with value true. | |
| tenduke::json::JSONArray * | getArray (const json::JSONObject *object, const std::string &propertyName) |
Helper to get JSON object property as tenduke::json::JSONArray. | |
| bool | getBool (const json::JSONObject *object, const std::string &propertyName, bool defaultValue=false) |
| Helper to get JSON object property as boolean. | |
| std::int32_t | getInt32 (const tenduke::json::JSONObject *object, const std::string &propertyName, std::int32_t defaultValue=0) |
Helper to get numeric JSON object property as std::int32_t. | |
| std::int64_t | getInt64 (const tenduke::json::JSONObject *object, const std::string &propertyName, std::int64_t defaultValue=0) |
Helper to get numeric JSON object property as std::int64_t. | |
| tenduke::json::JSONNumber * | getNumber (const tenduke::json::JSONObject *object, const std::string &propertyName) |
Helper to get JSON object property as tenduke::json::JSONNumber. | |
| tenduke::json::JSONObject * | getObject (const tenduke::json::JSONObject *object, const std::string &propertyName) |
Helper to get JSON object property as tenduke::json::JSONObject. | |
| std::string | getStdString (const tenduke::json::JSONObject &object, const std::string &propertyName, const std::string &defaultValue={}) |
Helper to get JSON object property as std::string. | |
| std::string | getStdString (const tenduke::json::JSONObject *object, const std::string &propertyName, const std::string &defaultValue={}) |
Helper to get JSON object property as std::string. | |
| std::vector< std::string > | toArrayOfStrings (const ::tenduke::json::JSONArray *array) |
Converts a tenduke::json::JSONArray to a flattened vector of strings. | |
| std::map< std::string, std::string > | toMapOfStrings (const tenduke::json::JSONObject *object) |
Converts a tenduke::json::JSONObject to a flattened map of strings, where the key is name of the object property and value is result of calling tenduke::json::JSONElement.asString() on the property element. | |
| tenduke::json::JSONArray * tenduke::json::castToArray | ( | const std::shared_ptr< tenduke::json::JSONElement > & | element | ) |
| tenduke::json::JSONArray * tenduke::json::castToArray | ( | const std::unique_ptr< tenduke::json::JSONElement > & | element | ) |
| xdjson::JSONArray * tenduke::json::castToArray | ( | tenduke::json::JSONElement * | element | ) |
| xdjson::JSONObject * tenduke::json::castToObject | ( | const std::shared_ptr< tenduke::json::JSONElement > & | element | ) |
Type-casts given element to JSONObject.
| element | - |
nullptr if the provided parameter is nullptr or if the element isNull() or isUndefined() | `::tenduke::json::JSONException` | if the element is not JSON object |
| xdjson::JSONObject * tenduke::json::castToObject | ( | const std::unique_ptr< tenduke::json::JSONElement > & | element | ) |
Type-casts given element to JSONObject.
| element | - |
nullptr if the provided parameter is nullptr or if the element isNull() or isUndefined() | `::tenduke::json::JSONException` | if the element is not JSON object |
| xdjson::JSONObject * tenduke::json::castToObject | ( | tenduke::json::JSONElement * | element | ) |
Type-casts given element to JSONObject.
| element | - |
nullptr if the provided parameter is nullptr or if the element isNull() or isUndefined() | `::tenduke::json::JSONException` | if the element is not JSON object |
| xdjson::JSONArray * tenduke::json::getArray | ( | const json::JSONObject * | object, |
| const std::string & | propertyName ) |
Helper to get JSON object property as tenduke::json::JSONArray.
| object | the JSON object |
| propertyName | name of the JSON object property |
tenduke::json::JSONArray. Returns nullptr, if object does not contain such property, or if the property is null or undefined. | `::tenduke::json::JSONException` | if the property is not JSON array. |
| bool tenduke::json::getBool | ( | const json::JSONObject * | object, |
| const std::string & | propertyName, | ||
| bool | defaultValue = false ) |
Helper to get JSON object property as boolean.
| object | the JSON object |
| propertyName | name of the JSON object property |
| defaultValue | default value to return if the object does not have such property |
true, if the JSON object has such property and the property is a JSON boolean with value true. Returns false if the property is a JSON boolean with value false. Returns parameter defaultValue if the JSON object does not have such property. | `::tenduke::json::JSONException` | if the property is not JSON boolean. |
| std::int32_t tenduke::json::getInt32 | ( | const tenduke::json::JSONObject * | object, |
| const std::string & | propertyName, | ||
| std::int32_t | defaultValue = 0 ) |
Helper to get numeric JSON object property as std::int32_t.
| object | the JSON object |
| propertyName | name of the JSON object property |
| defaultValue | default value to return if the object does not have such property |
std::int_32t. Returns parameter defaultValue if the JSON object does not have such property. | `::tenduke::json::JSONException` | if the property is not JSON number. |
| std::int64_t tenduke::json::getInt64 | ( | const tenduke::json::JSONObject * | object, |
| const std::string & | propertyName, | ||
| std::int64_t | defaultValue = 0 ) |
Helper to get numeric JSON object property as std::int64_t.
| object | the JSON object |
| propertyName | name of the JSON object property |
| defaultValue | default value to return if the object does not have such property |
std::int_64t. Returns parameter defaultValue if the JSON object does not have such property. | `::tenduke::json::JSONException` | if the property is not JSON number. |
| xdjson::JSONNumber * tenduke::json::getNumber | ( | const tenduke::json::JSONObject * | object, |
| const std::string & | propertyName ) |
Helper to get JSON object property as tenduke::json::JSONNumber.
| object | the JSON object |
| propertyName | name of the JSON object property |
nullptr if the JSON object does not have such property or if the property is null or undefined. | `::tenduke::json::JSONException` | if the property is not JSON number. |
| xdjson::JSONObject * tenduke::json::getObject | ( | const tenduke::json::JSONObject * | object, |
| const std::string & | propertyName ) |
Helper to get JSON object property as tenduke::json::JSONObject.
| object | the JSON object |
| propertyName | name of the JSON object property |
nullptr if the JSON object does not have such property or if the property is null or undefined. | `::tenduke::json::JSONException` | if the property is not JSON object. |
| std::string tenduke::json::getStdString | ( | const tenduke::json::JSONObject & | object, |
| const std::string & | propertyName, | ||
| const std::string & | defaultValue = {} ) |
Helper to get JSON object property as std::string.
The property does not need to be tenduke::json::JSONString. This returns result of calling tenduke::json::JSONElement.asString() on the property element.
This function does not throw exceptions.
| object | the JSON object |
| propertyName | name of the JSON object property |
| defaultValue | default value to return if no such property, or the property is null or undefined |
tenduke::json::JSONElement.asString() on the property element. Returns parameter defaultValue if the JSON object does not have such property or if the property is null or undefined. | std::string tenduke::json::getStdString | ( | const tenduke::json::JSONObject * | object, |
| const std::string & | propertyName, | ||
| const std::string & | defaultValue = {} ) |
Helper to get JSON object property as std::string.
The property does not need to be tenduke::json::JSONString. This returns result of calling tenduke::json::JSONElement.asString() on the property element.
This function does not throw exceptions.
| object | the JSON object |
| propertyName | name of the JSON object property |
| defaultValue | default value to return if no such property, or the property is null or undefined |
tenduke::json::JSONElement.asString() on the property element. Returns parameter defaultValue if the JSON object does not have such property or if the property is null or undefined. | bool tenduke::json::isBooleanTrue | ( | const JSONElement * | element | ) |
| bool tenduke::json::isBooleanTrue | ( | const std::shared_ptr< const JSONElement > & | element | ) |
| bool tenduke::json::isBooleanTrue | ( | const std::unique_ptr< const JSONElement > & | element | ) |
| std::vector< std::string > tenduke::json::toArrayOfStrings | ( | const ::tenduke::json::JSONArray * | array | ) |
Converts a tenduke::json::JSONArray to a flattened vector of strings.
Primitives (strings, numbers, booleans), will be string representations of themselves. For example elements of array ["a", 1, true] would be returned as "a", "1.000000", "true". JSON objects will be JSON.
| array | - |
| std::int64_t tenduke::json::toInt64 | ( | const JSONElement & | element, |
| bool | throwIfInvalid = true, | ||
| std::int64_t | defaultValue = 0 ) |
Returns given element as std::int_64t, assuming the element is JSONNumber.
| element | - |
| throwIfInvalid | if true, the method throws tenduke::json::JSONException if the element is not JSONNumber. If false, returns parameter defaultValue if the element is e.g. nullptr or JSONString. |
| defaultValue | default value to return if the provided element is not JSONNumber (or element is e.g. nullptr). See throwIfInvalid. |
| `::tenduke::json::JSONException` | if the element is not JSON number and throwIfInvalid is true. |
| std::int64_t tenduke::json::toInt64 | ( | const JSONElement * | element, |
| bool | throwIfInvalid = true, | ||
| std::int64_t | defaultValue = 0 ) |
Returns given element as std::int_64t, assuming the element is JSONNumber.
| element | - |
| throwIfInvalid | if true, the method throws tenduke::json::JSONException if the element is not JSONNumber. If false, returns parameter defaultValue if the element is e.g. nullptr or JSONString. |
| defaultValue | default value to return if the provided element is not JSONNumber (or element is e.g. nullptr). See throwIfInvalid. |
| `::tenduke::json::JSONException` | if the element is not JSON number and throwIfInvalid is true. |
| std::map< std::string, std::string > tenduke::json::toMapOfStrings | ( | const tenduke::json::JSONObject * | object | ) |
Converts a tenduke::json::JSONObject to a flattened map of strings, where the key is name of the object property and value is result of calling tenduke::json::JSONElement.asString() on the property element.
| object | the JSON object |