diff --git a/include/ArduinoJson/Internals/JsonObjectNode.hpp b/include/ArduinoJson/Internals/JsonObjectNode.hpp index 419c403b..45dae7c5 100644 --- a/include/ArduinoJson/Internals/JsonObjectNode.hpp +++ b/include/ArduinoJson/Internals/JsonObjectNode.hpp @@ -12,7 +12,7 @@ namespace ArduinoJson { namespace Internals { struct JsonObjectNode { - JsonObjectNode(const char* key) : content(key), next(NULL) {} + JsonObjectNode() : next(NULL) {} JsonPair content; JsonObjectNode* next; diff --git a/include/ArduinoJson/JsonObject.hpp b/include/ArduinoJson/JsonObject.hpp index 851a97f8..286e7006 100644 --- a/include/ArduinoJson/JsonObject.hpp +++ b/include/ArduinoJson/JsonObject.hpp @@ -67,7 +67,7 @@ class JsonObject : public Internals::JsonPrintable, JsonObject(JsonBuffer *buffer) : _buffer(buffer), _firstNode(NULL) {} JsonVariant &add(key_type key) { return (*this)[key]; } - Internals::JsonObjectNode *createNode(key_type key); + Internals::JsonObjectNode *createNode(); void addNode(Internals::JsonObjectNode *nodeToAdd); void removeNode(Internals::JsonObjectNode *nodeToRemove); diff --git a/include/ArduinoJson/JsonPair.hpp b/include/ArduinoJson/JsonPair.hpp index 143be11d..cf0b86fb 100644 --- a/include/ArduinoJson/JsonPair.hpp +++ b/include/ArduinoJson/JsonPair.hpp @@ -11,8 +11,6 @@ namespace ArduinoJson { struct JsonPair { - JsonPair(const char* k) : key(k) {} - const char* key; JsonVariant value; }; diff --git a/src/JsonObject.cpp b/src/JsonObject.cpp index 95b4a9ad..4a94f791 100644 --- a/src/JsonObject.cpp +++ b/src/JsonObject.cpp @@ -67,17 +67,18 @@ JsonObjectNode *JsonObject::getOrCreateNodeAt(const char *key) { JsonObjectNode *existingNode = getNodeAt(key); if (existingNode) return existingNode; - JsonObjectNode *newNode = createNode(key); - - if (newNode) addNode(newNode); + JsonObjectNode *newNode = createNode(); + if (!newNode) return NULL; + newNode->content.key = key; + addNode(newNode); return newNode; } -JsonObjectNode *JsonObject::createNode(const char *key) { +JsonObjectNode *JsonObject::createNode() { if (!_buffer) return NULL; void *ptr = _buffer->alloc(sizeof(JsonObjectNode)); - return ptr ? new (ptr) JsonObjectNode(key) : NULL; + return ptr ? new (ptr) JsonObjectNode() : NULL; } void JsonObject::addNode(JsonObjectNode *nodeToAdd) {