Remove the deprecated Json::Reader (#1546)

This commit is contained in:
An Tao 2023-03-26 17:03:19 +08:00 committed by GitHub
parent f0a011b14d
commit 120aaf249d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 3 deletions

View File

@ -1,15 +1,21 @@
#include "JsonConfigAdapter.h" #include "JsonConfigAdapter.h"
#include <fstream> #include <fstream>
#include <mutex>
using namespace drogon; using namespace drogon;
Json::Value JsonConfigAdapter::getJson(const std::string &content) const Json::Value JsonConfigAdapter::getJson(const std::string &content) const
noexcept(false) noexcept(false)
{ {
static std::once_flag once;
static Json::CharReaderBuilder builder;
std::call_once(once, []() { builder["collectComments"] = false; });
JSONCPP_STRING errs;
std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
Json::Value root; Json::Value root;
Json::Reader reader; if (!reader->parse(
if (!reader.parse(content, root)) content.c_str(), content.c_str() + content.size(), &root, &errs))
{ {
throw std::runtime_error("Failed to parse JSON"); throw std::runtime_error(errs);
} }
return root; return root;
} }