mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-15 19:42:12 +02:00
Test that adding the same value twice doesn't increase the size of the object
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
#include "JsonBuffer.h"
|
||||
#include "JsonObject.h"
|
||||
#include "JsonValue.h"
|
||||
//#include "JsonNode.h"
|
||||
|
||||
#include "JsonNode.h"
|
||||
#include <string.h>
|
||||
|
||||
//JsonValue& JsonObject::operator[](char const* key)
|
||||
//{
|
||||
@ -31,10 +31,53 @@
|
||||
// _node.asObjectNode.child = &newChild;
|
||||
//}
|
||||
|
||||
size_t JsonObject::size()
|
||||
{
|
||||
JsonNode* firstChild = _node->content.asObjectNode.child;
|
||||
|
||||
int size = 0;
|
||||
|
||||
for (JsonNode* child = firstChild; child; child = child->next)
|
||||
{
|
||||
size++;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
JsonValue JsonObject::operator[](char const* key)
|
||||
{
|
||||
_buffer->createNode();
|
||||
_buffer->createNode();
|
||||
_size++;
|
||||
return JsonValue();
|
||||
JsonNode* node = getOrCreateNodeAt(key);
|
||||
return JsonValue(/*node*/);
|
||||
}
|
||||
|
||||
JsonNode* JsonObject::getOrCreateNodeAt(char const* key)
|
||||
{
|
||||
if (!_node || _node->type != JSON_OBJECT) return 0;
|
||||
|
||||
JsonNode* firstChild = _node->content.asObjectNode.child;
|
||||
JsonNode* lastChild = 0;
|
||||
|
||||
for (JsonNode* child = firstChild; child; child = child->next)
|
||||
{
|
||||
const char* childKey = child->content.asKey.key;
|
||||
|
||||
if (!strcmp(childKey, key))
|
||||
return child->content.asKey.value;
|
||||
|
||||
lastChild = child;
|
||||
}
|
||||
|
||||
JsonNode* newValueNode = _buffer->createNode(JSON_UNDEFINED);
|
||||
|
||||
JsonNode* newKeyNode = _buffer->createNode(JSON_KEY);
|
||||
newKeyNode->content.asKey.key = key;
|
||||
newKeyNode->content.asKey.value = newValueNode;
|
||||
|
||||
if (lastChild)
|
||||
lastChild->next = newKeyNode;
|
||||
else
|
||||
_node->content.asObjectNode.child = newKeyNode;
|
||||
|
||||
return newValueNode;
|
||||
}
|
Reference in New Issue
Block a user