From: Gunnar Beutner Date: Thu, 28 Feb 2013 13:06:30 +0000 (+0100) Subject: Implement support for deserializing JSON arrays. X-Git-Tag: v0.0.2~343 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=959b7fa16aa68cd8d510b1bfdfa6c7c90c052170;p=icinga2 Implement support for deserializing JSON arrays. --- diff --git a/lib/base/value.cpp b/lib/base/value.cpp index d4a2486ae..6beda0dc9 100644 --- a/lib/base/value.cpp +++ b/lib/base/value.cpp @@ -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(); + + 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.")); }