From: Torsten Dreyer Date: Mon, 9 Mar 2015 15:17:20 +0000 (+0100) Subject: JSON Properties: encode NaN as null X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=fced50f4807d7421a66908de688ef4330ca26077;p=flightgear.git JSON Properties: encode NaN as null JSON doesn't know about NaN, probably null matches best --- diff --git a/src/Network/http/jsonprops.cxx b/src/Network/http/jsonprops.cxx index dc3ad58e0..e5c1a5085 100644 --- a/src/Network/http/jsonprops.cxx +++ b/src/Network/http/jsonprops.cxx @@ -20,6 +20,7 @@ #include "jsonprops.hxx" #include +#include 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;