AlexaClientSDK
3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
|
#include <JSONGenerator.h>
Public Member Functions | |
JsonGenerator () | |
~JsonGenerator ()=default | |
bool | isFinalized () |
bool | startObject (const std::string &key) |
bool | finishObject () |
bool | startArray (const std::string &key) |
bool | startArrayElement () |
bool | finishArrayElement () |
bool | finishArray () |
template<typename CollectionT , typename ValueT = typename CollectionT::value_type> | |
bool | addStringArray (const std::string &key, const CollectionT &collection) |
template<typename CollectionT , typename ValueT = typename CollectionT::value_type> | |
bool | addMembersArray (const std::string &key, const CollectionT &collection) |
bool | addRawJsonMember (const std::string &key, const std::string &json, bool validate=true) |
template<typename CollectionArrayT , typename CollectionValueT = typename CollectionArrayT::value_type, typename ValueT = typename CollectionValueT::value_type> | |
bool | addCollectionOfStringArray (const std::string &key, const CollectionArrayT &collection) |
std::string | toString (bool finalize=true) |
bool | addMember (const std::string &key, const char *value) |
bool | addMember (const std::string &key, const std::string &value) |
bool | addMember (const std::string &key, int64_t value) |
bool | addMember (const std::string &key, uint64_t value) |
bool | addMember (const std::string &key, int value) |
bool | addMember (const std::string &key, unsigned int value) |
bool | addMember (const std::string &key, bool value) |
bool | addMember (const std::string &key, double value) |
Utility class that can be used to build a json string.
E.g.: To build the following json: {"param1":"value","param2":{"param2.1":100}}. Use:
JsonGenerator generator; generator.addMember("param1", "value"); generator.startObject("param2"); generator.addMember("param2.1", 100); generator.toString();
For debugging purpose, you may be able to get the partial string by calling:
generator.toString(false)
alexaClientSDK::avsCommon::utils::json::JsonGenerator::JsonGenerator | ( | ) |
Constructor.
|
default |
Default destructor.
bool alexaClientSDK::avsCommon::utils::json::JsonGenerator::addCollectionOfStringArray | ( | const std::string & | key, |
const CollectionArrayT & | collection | ||
) |
Add a new array of arrays of strings with the given key
name. The arrays is built from the given collection
.
CollectionArrayT | Type of the array of collection. |
CollectionValueT | Type of the collection. |
ValueT | Type of the collection member. |
key | The name of the member. |
collection | The collection of string arrays. The strings are going to generate string elements. |
true
if it succeeded to add the new member and false
otherwise. bool alexaClientSDK::avsCommon::utils::json::JsonGenerator::addMember | ( | const std::string & | key, |
const char * | value | ||
) |
Add a new member with the key and value.
key | The name of the member. |
value | The value of the member. |
true
if it succeeded to add the new member and false
otherwise. bool alexaClientSDK::avsCommon::utils::json::JsonGenerator::addMember | ( | const std::string & | key, |
const std::string & | value | ||
) |
Add a new member with the key and value.
key | The name of the member. |
value | The value of the member. |
true
if it succeeded to add the new member and false
otherwise. bool alexaClientSDK::avsCommon::utils::json::JsonGenerator::addMember | ( | const std::string & | key, |
int64_t | value | ||
) |
Add a new member with the key and value.
key | The name of the member. |
value | The value of the member. |
true
if it succeeded to add the new member and false
otherwise. bool alexaClientSDK::avsCommon::utils::json::JsonGenerator::addMember | ( | const std::string & | key, |
uint64_t | value | ||
) |
Add a new member with the key and value.
key | The name of the member. |
value | The value of the member. |
true
if it succeeded to add the new member and false
otherwise. bool alexaClientSDK::avsCommon::utils::json::JsonGenerator::addMember | ( | const std::string & | key, |
int | value | ||
) |
Add a new member with the key and value.
key | The name of the member. |
value | The value of the member. |
true
if it succeeded to add the new member and false
otherwise. bool alexaClientSDK::avsCommon::utils::json::JsonGenerator::addMember | ( | const std::string & | key, |
unsigned int | value | ||
) |
Add a new member with the key and value.
key | The name of the member. |
value | The value of the member. |
true
if it succeeded to add the new member and false
otherwise. bool alexaClientSDK::avsCommon::utils::json::JsonGenerator::addMember | ( | const std::string & | key, |
bool | value | ||
) |
Add a new member with the key and value.
key | The name of the member. |
value | The value of the member. |
true
if it succeeded to add the new member and false
otherwise. bool alexaClientSDK::avsCommon::utils::json::JsonGenerator::addMember | ( | const std::string & | key, |
double | value | ||
) |
Add a new member with the key and value.
key | The name of the member. |
value | The value of the member. |
true
if it succeeded to add the new member and false
otherwise. bool alexaClientSDK::avsCommon::utils::json::JsonGenerator::addMembersArray | ( | const std::string & | key, |
const CollectionT & | collection | ||
) |
Add a new array with the given key
name. The array is built from the given collection
.
CollectionT | Type of the collection. |
ValueT | Type of the collection member. |
key | The name of the member. |
collection | The collection used to generate the array. Each item in the collection should be a string in the JSON format. Examples of valid items are: "\"val"", "123", and "true" representing a JSON string, a JSON integer, and a JSON boolean respectively. |
true
if it succeeded to add the new member and false
otherwise. bool alexaClientSDK::avsCommon::utils::json::JsonGenerator::addRawJsonMember | ( | const std::string & | key, |
const std::string & | json, | ||
bool | validate = true |
||
) |
Adds a raw json as a value to the given key.
key | The object key to the raw json provided. |
json | A string representation of a valid json. |
validate | Enable json validation for the raw json parameter. |
true
if it succeeded to add the raw json and false
otherwise. bool alexaClientSDK::avsCommon::utils::json::JsonGenerator::addStringArray | ( | const std::string & | key, |
const CollectionT & | collection | ||
) |
Add a new array of strings with the given key
name. The array is built from the given collection
.
CollectionT | Type of the collection. |
ValueT | Type of the collection member. |
key | The name of the member. |
collection | The collection used to generate the array. The strings are going to generate string elements. For vector of json elements, use addMembersArray . |
true
if it succeeded to add the new member and false
otherwise. bool alexaClientSDK::avsCommon::utils::json::JsonGenerator::finishArray | ( | ) |
Finish the last array that has been opened.
true
if the last object was closed false
if it fails. bool alexaClientSDK::avsCommon::utils::json::JsonGenerator::finishArrayElement | ( | ) |
Finish the last array element that has been opened.
true
if the last object was closed false
if it fails. bool alexaClientSDK::avsCommon::utils::json::JsonGenerator::finishObject | ( | ) |
Close the last object that has been opened.
true
if the last object was closed false
if it fails. bool alexaClientSDK::avsCommon::utils::json::JsonGenerator::isFinalized | ( | ) |
Checks whether the generator has been finalized (i.e., no changes can be made to the current json).
true
if it has been finalized, false
otherwise bool alexaClientSDK::avsCommon::utils::json::JsonGenerator::startArray | ( | const std::string & | key | ) |
Starts a new array with the given key.
key | The new array name. |
true
if it succeeds to create a new object and false
if it fails. bool alexaClientSDK::avsCommon::utils::json::JsonGenerator::startArrayElement | ( | ) |
Starts a new array object element.
true
if it succeeds to create a new object and false
if it fails. bool alexaClientSDK::avsCommon::utils::json::JsonGenerator::startObject | ( | const std::string & | key | ) |
Starts a new json object with the given key.
key | The new object name. |
true
if it succeeds to create a new object and false
if it fails. std::string alexaClientSDK::avsCommon::utils::json::JsonGenerator::toString | ( | bool | finalize = true | ) |
Return the string representation of the object.
finalize | If set to true the object will be finalized and the string returned will be a complete json document. If false , the returned string will represent the current state of the json generation which could be partial. |
AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0