Implement support for deserializing JSON arrays.

This commit is contained in:
Gunnar Beutner 2013-02-28 14:06:30 +01:00
parent 3a99842f90
commit 959b7fa16a
1 changed files with 9 additions and 1 deletions

View File

@ -105,7 +105,15 @@ Value Value::FromJson(cJSON *json)
return Dictionary::FromJson(json); return Dictionary::FromJson(json);
else if (json->type == cJSON_NULL) else if (json->type == cJSON_NULL)
return Value(); 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.")); BOOST_THROW_EXCEPTION(invalid_argument("Unsupported JSON type."));
} }