From 258b0472b203327c0dc05f733e0eac90b363d8f4 Mon Sep 17 00:00:00 2001 From: Evelyn Mawrey <23264638+evemawrey@users.noreply.github.com> Date: Wed, 8 May 2024 00:35:23 -0400 Subject: [PATCH] fix: update to use array index operator notation (#123) --- src/ConfigManager.cpp | 4 ++-- src/ConfigManager.h | 18 +++++++----------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/ConfigManager.cpp b/src/ConfigManager.cpp index 68f3200..1c45499 100644 --- a/src/ConfigManager.cpp +++ b/src/ConfigManager.cpp @@ -492,8 +492,8 @@ void ConfigManager::handleAPPost() { if (isJson) { JsonObject obj = decodeJson(server->arg("plain")); - ssid = obj.getMember("ssid").as(); - password = obj.getMember("password").as(); + ssid = String((const char*)obj["ssid"]); + password = String((const char*)obj["password"]); } else { ssid = server->arg("ssid"); password = server->arg("password"); diff --git a/src/ConfigManager.h b/src/ConfigManager.h index 7a59445..bc99bef 100644 --- a/src/ConfigManager.h +++ b/src/ConfigManager.h @@ -75,15 +75,13 @@ class ConfigParameter : public BaseParameter { void update(T value) { *ptr = value; } void fromJson(JsonObject* json) { - if (json->containsKey(name) && json->getMember(name).is()) { - this->update(json->getMember(name).as()); + const T value = (*json)[name]; + if (value) { + this->update(value); } } - void toJson(JsonObject* json) { - // json->set(name, *ptr); - json->getOrAddMember(name).set(*ptr); - } + void toJson(JsonObject* json) { (*json)[name] = *ptr; } void clearData() { DebugPrint("Clearing: "); @@ -121,15 +119,13 @@ class ConfigStringParameter : public BaseParameter { } void fromJson(JsonObject* json) { - if (json->containsKey(name) && json->getMember(name).is()) { - const char* value = json->getMember(name).as(); + const char* value = (*json)[name]; + if (value) { this->update(value); } } - void toJson(JsonObject* json) { - json->getOrAddMember(name).set((const char*)ptr); - } + void toJson(JsonObject* json) { (*json)[name] = (const char*)ptr; } void clearData() { DebugPrint("Clearing: ");