mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-28 23:22:19 +03:00
json utils updated
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
#include "Global.h"
|
||||
#include "Utils/FileUtils.h"
|
||||
|
||||
//=================================================================================
|
||||
//depricated======================================================================
|
||||
String jsonReadStr(String& json, String name) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
@@ -27,6 +27,51 @@ int jsonReadInt(String& json, String name) {
|
||||
return doc[name].as<int>();
|
||||
}
|
||||
|
||||
//new==============================================================================
|
||||
bool jsonReadFromStr(String& json, String key, String& 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<String>();
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool jsonReadFromStr(String& json, String key, bool& 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<bool>();
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool jsonReadFromStr(String& json, String key, int& 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<int>();
|
||||
return ret;
|
||||
}
|
||||
//=================================================================================
|
||||
String jsonWriteStr(String& json, String name, String value) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
|
||||
Reference in New Issue
Block a user