]> granicus.if.org Git - icinga2/commitdiff
Implement support for deserializing JSON arrays.
authorGunnar Beutner <gunnar.beutner@netways.de>
Thu, 28 Feb 2013 13:06:30 +0000 (14:06 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Thu, 28 Feb 2013 13:06:30 +0000 (14:06 +0100)
lib/base/value.cpp

index d4a2486ae1d40ee3dd0c9afd30268f192cded982..6beda0dc9ccf74a237ad79403a54dad9f6095ee3 100644 (file)
@@ -105,7 +105,15 @@ Value Value::FromJson(cJSON *json)
                return Dictionary::FromJson(json);
        else if (json->type == cJSON_NULL)
                return Value();
-       else
+       else if (json->type == cJSON_Array) {
+               Dictionary::Ptr dict = boost::make_shared<Dictionary>();
+
+               for (cJSON *i = json->child; i != NULL; i = i->next) {
+                       dict->Add(Value::FromJson(i));
+               }
+
+               return dict;
+       } else
                BOOST_THROW_EXCEPTION(invalid_argument("Unsupported JSON type."));
 }