mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
json обмен между вебом и esp
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "Utils/FileUtils.h"
|
||||
|
||||
//================================================================================
|
||||
// new================================================================================
|
||||
String jsonReadStrDoc(DynamicJsonDocument& doc, String name) {
|
||||
return doc[name].as<String>();
|
||||
}
|
||||
@@ -57,6 +57,63 @@ bool jsonRead(String& json, String key, int& value) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// new==============================================================================
|
||||
bool jsonWriteStr_(String& json, String key, String value) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
ret = false;
|
||||
}
|
||||
doc[key] = value;
|
||||
json = "";
|
||||
serializeJson(doc, json);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool jsonWriteBool_(String& json, String key, bool value) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
ret = false;
|
||||
}
|
||||
doc[key] = value;
|
||||
json = "";
|
||||
serializeJson(doc, json);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool jsonWriteInt_(String& json, String key, int value) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
ret = false;
|
||||
}
|
||||
doc[key] = value;
|
||||
json = "";
|
||||
serializeJson(doc, json);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool jsonWriteFloat_(String& json, String key, float value) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
ret = false;
|
||||
}
|
||||
doc[key] = value;
|
||||
json = "";
|
||||
serializeJson(doc, json);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// depricated======================================================================
|
||||
String jsonReadStr(String& json, String name) {
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
@@ -119,62 +176,3 @@ String jsonWriteFloat(String& json, String name, float value) {
|
||||
serializeJson(doc, json);
|
||||
return json;
|
||||
}
|
||||
|
||||
// new==============================================================================
|
||||
bool jsonWriteStr_(String& json, String key, String value) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
ret = false;
|
||||
}
|
||||
doc[key] = value;
|
||||
json = "";
|
||||
serializeJson(doc, json);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool jsonWriteBool_(String& json, String key, bool value) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
ret = false;
|
||||
}
|
||||
doc[key] = value;
|
||||
json = "";
|
||||
serializeJson(doc, json);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool jsonWriteInt_(String& json, String key, int value) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
ret = false;
|
||||
}
|
||||
doc[key] = value;
|
||||
json = "";
|
||||
serializeJson(doc, json);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool jsonWriteFloat_(String& json, String key, float value) {
|
||||
bool ret = true;
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
DeserializationError error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
SerialPrint("EE", F("jsonWrite"), error.f_str());
|
||||
ret = false;
|
||||
}
|
||||
doc[key] = value;
|
||||
json = "";
|
||||
serializeJson(doc, json);
|
||||
return ret;
|
||||
}
|
||||
|
||||
//=================================================================================
|
||||
|
||||
Reference in New Issue
Block a user