diff options
author | Loïc Blot <nerzhul@users.noreply.github.com> | 2017-09-26 20:30:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-26 20:30:14 +0200 |
commit | 50423d8c729ee133035e3bb1e244bfbd1bdc0ef0 (patch) | |
tree | 4605bc80aed2d0f729047697b23e709ade2510e5 /src/convert_json.cpp | |
parent | f7e57a0d20879e1d1956e36d782a3ab98aa84e38 (diff) | |
download | hax-minetest-server-50423d8c729ee133035e3bb1e244bfbd1bdc0ef0.tar.gz hax-minetest-server-50423d8c729ee133035e3bb1e244bfbd1bdc0ef0.zip |
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
Diffstat (limited to '')
-rw-r--r-- | src/convert_json.cpp | 19 |
1 files changed, 16 insertions, 3 deletions
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<Json::StreamWriter> writer(builder.newStreamWriter()); + writer->write(value, &oss); + return oss.str(); +} |