Utility for parsing JSON.
More...
#include <RTJsonParser.h>
Utility for parsing JSON.
The result of parsing is represented by a tree of
- See also
- RTJsonResult objects.
◆ parseJsonString()
bool RTJsonParser::parseJsonString |
( |
RTJsonResult & |
result, |
|
|
const std::string & |
jsonStr |
|
) |
| |
Parse a JSON string.
- Parameters
-
[out] | result | RTJsonResult object representing the parsed JSON |
[in] | jsonStr | JSON string to parse |
- Returns
- true if successfully parsed, false otherwise
const std::string jsonStr = R"({ "event" : "ping", "bVal" : true, "array" : [ 1, 2 ] })";
if(ret)
{
std::cout <<
"event type: " << result[
"event"].
get_type() << std::endl;
std::cout <<
"event: " << result[
"event"].
get_string() << std::endl;
std::cout <<
"bVal: " << result[
"bVal"].
get_bool() << std::endl;
std::cout <<
"array: " << result[
"array"][0].
get_int() << std::endl;
}
Utility for parsing JSON.
Definition: RTJsonParser.h:23
bool parseJsonString(RTJsonResult &result, const std::string &jsonStr)
Parse a JSON string.
Represents the result of parsing a JSON string.
Definition: RTJsonResult.h:29
const std::string & get_string() const
Get a string representation of the JSON value.
bool get_bool() const
Interpret the JSON value as a bool.
RTJsonType get_type() const
Get the type of JSON value represented by the RTJsonResult.
int get_int() const
Interpret the JSON value as an int.
The documentation for this class was generated from the following file: