C++ TargetRTS
Loading...
Searching...
No Matches
Public Member Functions | List of all members
RTJsonParser Class Reference

Utility for parsing JSON. More...

#include <RTJsonParser.h>

Public Member Functions

bool parseJsonString (RTJsonResult &result, const std::string &jsonStr)
 Parse a JSON string.
 

Detailed Description

Utility for parsing JSON.

The result of parsing is represented by a tree of

See also
RTJsonResult objects.

Member Function Documentation

◆ parseJsonString()

bool RTJsonParser::parseJsonString ( RTJsonResult result,
const std::string &  jsonStr 
)

Parse a JSON string.

Parameters
[out]resultRTJsonResult object representing the parsed JSON
[in]jsonStrJSON string to parse
Returns
true if successfully parsed, false otherwise
const std::string jsonStr = R"({ "event" : "ping", "bVal" : true, "array" : [ 1, 2 ] })";
RTJsonResult result;
bool ret = parse.parseJsonString(result, jsonStr);
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:48
bool parseJsonString(RTJsonResult &result, const std::string &jsonStr)
Parse a JSON string.
Represents the result of parsing a JSON string.
Definition: RTJsonResult.h:28
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: