From 50423d8c729ee133035e3bb1e244bfbd1bdc0ef0 Mon Sep 17 00:00:00 2001 From: Loïc Blot Date: Tue, 26 Sep 2017 20:30:14 +0200 Subject: Update JsonCPP to 1.8.3 (#6466) * Update JsonCPP to 1.8.3 * Fix deprecated functions Json::FastWriter, Json::StyledWriter and Json::Reader are marked deprecated since 1.1 and are deprecated in 0.8 but not shown at compilation time. Use new methods to serialize/deserialize --- src/convert_json.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/convert_json.cpp') diff --git a/src/convert_json.cpp b/src/convert_json.cpp index 1343903b4..bfd7f39c4 100644 --- a/src/convert_json.cpp +++ b/src/convert_json.cpp @@ -46,12 +46,15 @@ Json::Value fetchJsonValue(const std::string &url, return Json::Value(); } Json::Value root; - Json::Reader reader; std::istringstream stream(fetch_result.data); - if (!reader.parse(stream, root)) { + Json::CharReaderBuilder builder; + builder.settings_["collectComments"] = false; + std::string errs; + + if (!Json::parseFromStream(builder, stream, &root, &errs)) { errorstream << "URL: " << url << std::endl; - errorstream << "Failed to parse json data " << reader.getFormattedErrorMessages(); + errorstream << "Failed to parse json data " << errs << std::endl; if (fetch_result.data.size() > 100) { errorstream << "Data (" << fetch_result.data.size() << " bytes) printed to warningstream." << std::endl; @@ -64,3 +67,13 @@ Json::Value fetchJsonValue(const std::string &url, return root; } + +std::string fastWriteJson(const Json::Value &value) +{ + std::ostringstream oss; + Json::StreamWriterBuilder builder; + builder["indentation"] = ""; + std::unique_ptr writer(builder.newStreamWriter()); + writer->write(value, &oss); + return oss.str(); +} -- cgit v1.2.3