1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

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
This commit is contained in:
Loïc Blot 2017-09-26 20:30:14 +02:00 committed by GitHub
parent f7e57a0d20
commit 50423d8c72
10 changed files with 549 additions and 103 deletions

View file

@ -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();
}