mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-07-25 16:27:33 +02:00
Epic refactoring in progress...
This commit is contained in:
@ -6,62 +6,16 @@
|
||||
|
||||
#include "ArduinoJson/JsonObject.hpp"
|
||||
|
||||
#include <string.h> // for strcmp
|
||||
|
||||
#include "ArduinoJson/JsonBuffer.hpp"
|
||||
#include "ArduinoJson/JsonValue.hpp"
|
||||
#include "ArduinoJson/Internals/JsonNode.hpp"
|
||||
#include "ArduinoJson/Internals/StringBuilder.hpp"
|
||||
|
||||
using namespace ArduinoJson;
|
||||
using namespace ArduinoJson::Internals;
|
||||
|
||||
JsonValue JsonObject::operator[](char const *key) {
|
||||
JsonNode *node = getOrCreateValueAt(key);
|
||||
return JsonValueInternal(node);
|
||||
return JsonValue(_impl ? (*_impl)[key] : NULL);
|
||||
}
|
||||
|
||||
void JsonObject::remove(char const *key) {
|
||||
JsonNode *nodeToRemove = getPairAt(key);
|
||||
if (nodeToRemove) removeChild(nodeToRemove);
|
||||
JsonArray JsonObject::createNestedArray(key_type key) {
|
||||
return JsonArray(_impl ? _impl->createNestedArray(key) : NULL);
|
||||
}
|
||||
|
||||
JsonArray JsonObject::createNestedArray(char const *key) {
|
||||
JsonNode *node = getOrCreateValueAt(key);
|
||||
|
||||
if (node) node->setAsArray(_node->getContainerBuffer());
|
||||
|
||||
return JsonArray(node);
|
||||
}
|
||||
|
||||
JsonObject JsonObject::createNestedObject(char const *key) {
|
||||
JsonNode *node = getOrCreateValueAt(key);
|
||||
|
||||
if (node) node->setAsObject(_node->getContainerBuffer());
|
||||
|
||||
return JsonObject(node);
|
||||
}
|
||||
|
||||
JsonNode *JsonObject::getPairAt(const char *key) {
|
||||
for (JsonNode *node = firstChild(); node; node = node->next) {
|
||||
if (!strcmp(node->getAsObjectKey(), key)) return node;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
JsonNode *JsonObject::getOrCreateValueAt(const char *key) {
|
||||
JsonNode *existingNode = getPairAt(key);
|
||||
if (existingNode) return existingNode->getAsObjectValue();
|
||||
|
||||
JsonNode *newValueNode = createNode();
|
||||
if (!newValueNode) return 0;
|
||||
|
||||
JsonNode *newKeyNode = createNode();
|
||||
if (!newKeyNode) return 0;
|
||||
|
||||
newKeyNode->setAsObjectKeyValue(key, newValueNode);
|
||||
|
||||
addChild(newKeyNode);
|
||||
|
||||
return newValueNode;
|
||||
JsonObject JsonObject::createNestedObject(key_type key) {
|
||||
return JsonObject(_impl ? _impl->createNestedObject(key) : NULL);
|
||||
}
|
||||
|
Reference in New Issue
Block a user