Added JsonObject::createNestedArray()

This commit is contained in:
Benoit Blanchon
2014-10-07 12:11:10 +02:00
parent e28119f03b
commit 09b6f71853
3 changed files with 32 additions and 19 deletions

View File

@ -33,17 +33,15 @@ void JsonObject::remove(char const* key)
}
}
JsonArray JsonObject::createNestedArray(char const* key)
{
JsonNode* node = createContainerNodeAt(key, JSON_ARRAY);
return JsonArray(node);
}
JsonObject JsonObject::createNestedObject(char const* key)
{
JsonNode* node = getOrCreateNodeAt(key);
if (node)
{
node->type = JSON_OBJECT;
node->content.asContainer.child = 0;
node->content.asContainer.buffer = _node->content.asContainer.buffer;
}
JsonNode* node = createContainerNodeAt(key, JSON_OBJECT);
return JsonObject(node);
}
@ -72,3 +70,15 @@ JsonNode* JsonObject::getOrCreateNodeAt(const char* key)
return newValueNode;
}
JsonNode* JsonObject::createContainerNodeAt(char const* key, JsonNodeType type)
{
JsonNode* node = getOrCreateNodeAt(key);
if (!node) return 0;
node->type = type;
node->content.asContainer.child = 0;
node->content.asContainer.buffer = _node->content.asContainer.buffer;
return node;
}

View File

@ -2,6 +2,7 @@
#include "JsonContainer.h"
class JsonArray;
class JsonValue;
struct JsonNode;
@ -21,8 +22,10 @@ public:
JsonValue operator[](const char* key);
void remove(const char* key);
JsonArray createNestedArray(const char* key);
JsonObject createNestedObject(const char* key);
private:
JsonNode* getOrCreateNodeAt(char const* key);
JsonNode* getOrCreateNodeAt(const char* key);
JsonNode* createContainerNodeAt(const char* key, JsonNodeType type);
};