diff --git a/JsonGenerator/EscapedString.h b/JsonGenerator/EscapedString.h index 91f90d0a..6f573e11 100644 --- a/JsonGenerator/EscapedString.h +++ b/JsonGenerator/EscapedString.h @@ -10,10 +10,10 @@ class EscapedString { public: - EscapedString(const char* s) - : rawString(s) - { + void set(const char* s) + { + rawString = s; } size_t printTo(Print&) const; diff --git a/JsonGenerator/JsonHashTable.h b/JsonGenerator/JsonHashTable.h index 5acc6a2f..efbdf35c 100644 --- a/JsonGenerator/JsonHashTable.h +++ b/JsonGenerator/JsonHashTable.h @@ -5,6 +5,7 @@ #pragma once +#include "EscapedString.h" #include "JsonObjectBase.h" namespace ArduinoJson @@ -26,7 +27,7 @@ namespace ArduinoJson { if (itemCount >= N) return; - items[itemCount].key = key; + items[itemCount].key.set(key); items[itemCount].value.set(value); itemCount++; } @@ -36,7 +37,7 @@ namespace ArduinoJson { if (itemCount >= N) return; - items[itemCount].key = key; + items[itemCount].key.set(key); items[itemCount].value.set(value); itemCount++; } @@ -47,7 +48,7 @@ namespace ArduinoJson struct KeyValuePair { - const char* key; + EscapedString key; JsonValue value; }; @@ -62,15 +63,12 @@ namespace ArduinoJson for (int i = 0; i < itemCount; i++) { - JsonValue key; - key.set(items[i].key); - if (i > 0) { n += p.write(','); } - n += key.printTo(p); + n += items[i].key.printTo(p); n += p.write(':'); n += items[i].value.printTo(p); } diff --git a/JsonGenerator/JsonValue.cpp b/JsonGenerator/JsonValue.cpp index e8f11316..1398b07a 100644 --- a/JsonGenerator/JsonValue.cpp +++ b/JsonGenerator/JsonValue.cpp @@ -28,6 +28,5 @@ size_t JsonValue::printPrintableTo(const Content& c, Print& p) size_t JsonValue::printStringTo(const Content& c, Print& p) { - EscapedString s(c.asString); - return s.printTo(p); + return c.asString.printTo(p); } \ No newline at end of file diff --git a/JsonGenerator/JsonValue.h b/JsonGenerator/JsonValue.h index 0e1af089..cf45aa93 100644 --- a/JsonGenerator/JsonValue.h +++ b/JsonGenerator/JsonValue.h @@ -5,6 +5,7 @@ #pragma once +#include "EscapedString.h" #include "Printable.h" #include "StringBuilder.h" @@ -43,7 +44,7 @@ namespace ArduinoJson void set(const char* value) { printToImpl = &printStringTo; - content.asString = value; + content.asString.set(value); } template @@ -62,11 +63,11 @@ namespace ArduinoJson private: union Content { - bool asBool; - long asLong; - Printable* asPrintable; - const char* asString; - double asDouble; + bool asBool; + long asLong; + Printable* asPrintable; + EscapedString asString; + double asDouble; }; Content content;