]> git.mxchange.org Git - flightgear.git/commitdiff
Type-correct decoding of JSON to props.
authorJames Turner <zakalawe@mac.com>
Thu, 12 Jun 2014 18:58:13 +0000 (19:58 +0100)
committerJames Turner <zakalawe@mac.com>
Thu, 12 Jun 2014 18:58:13 +0000 (19:58 +0100)
src/Network/http/jsonprops.cxx

index 3bb3633fb070e54c3cbaff7bedc335395ed3dfa5..1745609aaebb8e51c7359a77f3c6ac4a4915bd99 100644 (file)
@@ -114,18 +114,30 @@ void JSON::toProp(cJSON * json, SGPropertyNode_ptr base)
       toProp(cJSON_GetArrayItem(children, i), n);
     }
   } else {
-    //TODO: set correct type
-    /*
-     char * type = "";
-     cj = cJSON_GetObjectItem( json, "type" );
-     if( NULL != cj ) type = cj->valuestring;
-     */
-    char * value = NULL;
     cj = cJSON_GetObjectItem(json, "value");
-    if (NULL != cj) value = cj->valuestring;
-
-    if (NULL != value) n->setUnspecifiedValue(value);
-  }
+    if (NULL != cj) {
+      switch ( cj->type ) {
+      case cJSON_String:
+        n->setStringValue(cj->valuestring);
+        break;
+        
+      case cJSON_Number:
+        n->setDoubleValue(cj->valuedouble);
+        break;
+        
+      case cJSON_True:
+        n->setBoolValue(true);
+        break;
+        
+      case cJSON_False:
+        n->setBoolValue(false);
+        break;
+          
+      default:
+        break;
+      }
+    } // of have value
+  } // of no children
 }
 
 void JSON::addChildrenToProp(cJSON * json, SGPropertyNode_ptr n)