JSON Library Usage
Example:
// Include header file
#include <json/json.h>
Json::Value root;
root["name"] = "plugin";
// Add array
root["array"].append("arr0");
root["array"].append("arr1");
// Nested object
root["obj"]["inner"] = 1;
// Check if key exists
if (root.isMember("obj") && root["obj"].isObject() && root["obj"].isMember("inner") && root["obj"]["inner"].isInt()) {
LOG(INFO)<< root["obj"]["inner"].asInt();
}
// Process array field
if (root.isMember("array") && root["array"].isArray()) {
for (const auto& item : root["array"]) {
LOG(INFO)<<item.asString();
}
}
// Serialize string
Json::StreamWriterBuilder writer;
std::string str = Json::writeString(writer, root);
LOG(INFO) << "json string:\n" << str ;
For more advanced usage of the json library, please refer to the header file.