[icinga-checkins] icinga.org: icinga2/master: Implement support for deserializing JSON arrays .

git at icinga.org git at icinga.org
Thu Feb 28 14:06:39 CET 2013


Module: icinga2
Branch: master
Commit: 959b7fa16aa68cd8d510b1bfdfa6c7c90c052170
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=959b7fa16aa68cd8d510b1bfdfa6c7c90c052170

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Thu Feb 28 14:06:30 2013 +0100

Implement support for deserializing JSON arrays.

---

 lib/base/value.cpp |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/lib/base/value.cpp b/lib/base/value.cpp
index d4a2486..6beda0d 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<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."));
 }
 





More information about the icinga-checkins mailing list