mirror of
https://gitlab.com/splashmapper/splash.git
synced 2026-06-16 12:33:50 +02:00
Fix conversion of real numbers from json
This commit is contained in:
+14
-8
@@ -346,6 +346,12 @@ bool loadJsonFile(const std::string& filename, Json::Value& configuration)
|
||||
/*************/
|
||||
Values jsonToValues(const Json::Value& values)
|
||||
{
|
||||
// When converting from json to values, we start
|
||||
// by trying to convert to the more complex type
|
||||
// then we go down. So we start with double, then
|
||||
// integer and then boolean. This prevents converting
|
||||
// double to integer by error, for instance when
|
||||
// handling the value `1.0`.
|
||||
Values outValues;
|
||||
|
||||
if (values.isBool())
|
||||
@@ -358,12 +364,12 @@ Values jsonToValues(const Json::Value& values)
|
||||
{
|
||||
for (const auto& v : values)
|
||||
{
|
||||
if (v.isBool())
|
||||
outValues.emplace_back(v.asBool());
|
||||
if (v.isDouble())
|
||||
outValues.emplace_back(v.asFloat());
|
||||
else if (v.isInt())
|
||||
outValues.emplace_back(v.asInt());
|
||||
else if (v.isDouble())
|
||||
outValues.emplace_back(v.asFloat());
|
||||
else if (v.isBool())
|
||||
outValues.emplace_back(v.asBool());
|
||||
else if (v.isArray() || v.isObject())
|
||||
outValues.emplace_back(jsonToValues(v));
|
||||
else
|
||||
@@ -376,12 +382,12 @@ Values jsonToValues(const Json::Value& values)
|
||||
int index = 0;
|
||||
for (const auto& v : values)
|
||||
{
|
||||
if (v.isBool())
|
||||
outValues.emplace_back(v.asBool(), names[index]);
|
||||
if (v.isDouble())
|
||||
outValues.emplace_back(v.asFloat(), names[index]);
|
||||
else if (v.isInt())
|
||||
outValues.emplace_back(v.asInt(), names[index]);
|
||||
else if (v.isDouble())
|
||||
outValues.emplace_back(v.asFloat(), names[index]);
|
||||
else if (v.isBool())
|
||||
outValues.emplace_back(v.asBool(), names[index]);
|
||||
else if (v.isArray() || v.isObject())
|
||||
outValues.emplace_back(jsonToValues(v), names[index]);
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user