diff --git a/src/utils/JsonUtils.cpp b/src/utils/JsonUtils.cpp index 7c42034a..8e9e39a1 100644 --- a/src/utils/JsonUtils.cpp +++ b/src/utils/JsonUtils.cpp @@ -12,6 +12,21 @@ void jsonWriteStrDoc(DynamicJsonDocument& doc, String name, String value) { } // new============================================================================== +bool jsonRead(String& json, String key, float& value) { + bool ret = true; + DynamicJsonDocument doc(JSON_BUFFER_SIZE); + DeserializationError error = deserializeJson(doc, json); + if (error) { + SerialPrint("EE", F("jsonRead"), error.f_str()); + ret = false; + } else if (!doc.containsKey(key)) { + SerialPrint("EE", F("jsonRead"), key + " missing"); + ret = false; + } + value = doc[key].as(); + return ret; +} + bool jsonRead(String& json, String key, String& value) { bool ret = true; DynamicJsonDocument doc(JSON_BUFFER_SIZE);