From fced50f4807d7421a66908de688ef4330ca26077 Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Mon, 9 Mar 2015 16:17:20 +0100 Subject: [PATCH] JSON Properties: encode NaN as null JSON doesn't know about NaN, probably null matches best --- src/Network/http/jsonprops.cxx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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;