jsoncpp 升级1.9.5

Signed-off-by: zt147369 <zhangting201@huawei.com>
This commit is contained in:
zt147369
2023-03-10 09:16:32 +00:00
parent d48008ac97
commit 855b19ce1e
68 changed files with 1234 additions and 1193 deletions
+5 -6
View File
@@ -1,6 +1,6 @@
#include "json/json.h"
#include <cstdlib>
#include <iostream>
#include <memory>
/**
* \brief Parse a raw string into Value object using the CharReaderBuilder
* class, or the legacy Reader class.
@@ -11,9 +11,9 @@
* 20
*/
int main() {
const std::string rawJson = "{\"Age\": 20, \"Name\": \"colin\"}";
const int rawJsonLength = static_cast<int>(rawJson.length());
JSONCPP_CONST bool shouldUseOldWay = false;
const std::string rawJson = R"({"Age": 20, "Name": "colin"})";
const auto rawJsonLength = static_cast<int>(rawJson.length());
constexpr bool shouldUseOldWay = false;
JSONCPP_STRING err;
Json::Value root;
@@ -22,13 +22,12 @@ int main() {
reader.parse(rawJson, root);
} else {
Json::CharReaderBuilder builder;
Json::CharReader* reader(builder.newCharReader());
const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
if (!reader->parse(rawJson.c_str(), rawJson.c_str() + rawJsonLength, &root,
&err)) {
std::cout << "error" << std::endl;
return EXIT_FAILURE;
}
delete reader;
}
const std::string name = root["Name"].asString();
const int age = root["Age"].asInt();