Benoit Blanchon 11 лет назад
Родитель
Сommit
5d0e326bfd

+ 1 - 1
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;

+ 1 - 1
include/ArduinoJson/JsonObject.hpp

@@ -67,7 +67,7 @@ class JsonObject : public Internals::JsonPrintable<JsonObject>,
   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);
 

+ 0 - 2
include/ArduinoJson/JsonPair.hpp

@@ -11,8 +11,6 @@
 namespace ArduinoJson {
 
 struct JsonPair {
-  JsonPair(const char* k) : key(k) {}
-
   const char* key;
   JsonVariant value;
 };

+ 6 - 5
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) {