1
0
Fork 0

JSON Properties: encode NaN as null

JSON doesn't know about NaN, probably null matches best
This commit is contained in:
Torsten Dreyer 2015-03-09 16:17:20 +01:00
parent 8b141025cd
commit fced50f480

View file

@ -20,6 +20,7 @@
#include "jsonprops.hxx"
#include <simgear/misc/strutils.hxx>
#include <simgear/math/SGMath.hxx>
namespace flightgear {
namespace http {
@ -82,9 +83,11 @@ cJSON * JSON::toJson(SGPropertyNode_ptr n, int depth, double timestamp )
case simgear::props::INT:
case simgear::props::LONG:
case simgear::props::FLOAT:
case simgear::props::DOUBLE:
cJSON_AddItemToObject(json, "value", cJSON_CreateNumber(n->getDoubleValue()));
case simgear::props::DOUBLE: {
double val = n->getDoubleValue();
cJSON_AddItemToObject(json, "value", SGMiscd::isNaN(val) ? cJSON_CreateNull() : cJSON_CreateNumber(val));
break;
}
default:
cJSON_AddItemToObject(json, "value", cJSON_CreateString(n->getStringValue()));
break;