diff --git a/Changelog b/Changelog index 80a4a9d..5972726 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,8 @@ Version 0.4: ============= +2026-04-19: +- JSONElement: adding SetArray function to create an valid empty array + 2026-04-17: - adding function to request a certain headline - base64decode increase the outputbuffer by 2 bytes for null-temrinated strings diff --git a/UDPTCPNetwork-json.h b/UDPTCPNetwork-json.h index a4ae61a..54a6a33 100644 --- a/UDPTCPNetwork-json.h +++ b/UDPTCPNetwork-json.h @@ -29,6 +29,7 @@ public: void Set (std::string n, int64_t v); void Set (std::string n, std::string v); void SetArray (std::string n, std::list *l); + void SetArray (std::string n); void SetAddArray (std::string n, std::string jpstring); void SetObject (std::string n, std::string s); static std::string StringAddEscape(std::string *s); diff --git a/json.cc b/json.cc index d74c293..d44b9e3 100644 --- a/json.cc +++ b/json.cc @@ -533,12 +533,19 @@ void JSONElement::Set (std::string n, std::string v) { }; +void JSONElement::SetArray (std::string n) { + name = n; + type = JSON_T_ARRAY; + value = "[]"; +}; + + void JSONElement::SetArray (std::string n, std::list *l) { std::list::iterator iter; name = n; value = "["; - type = JSON_T_STRING; + type = JSON_T_ARRAY; for (iter = l->begin(); iter != l->end(); iter++) { if (iter != l->begin()) value += ",";