mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
arduino json 6
This commit is contained in:
@@ -1,53 +1,110 @@
|
||||
#include "Utils/JsonUtils.h"
|
||||
#include "Utils/FileUtils.h"
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
#include "Global.h"
|
||||
#include "Utils/FileUtils.h"
|
||||
|
||||
//String jsonReadStr(String& json, String name) {
|
||||
// DynamicJsonBuffer jsonBuffer;
|
||||
// JsonObject& root = jsonBuffer.parseObject(json);
|
||||
// return root[name].as<String>();
|
||||
//}
|
||||
//
|
||||
//boolean jsonReadBool(String& json, String name) {
|
||||
// DynamicJsonBuffer jsonBuffer;
|
||||
// JsonObject& root = jsonBuffer.parseObject(json);
|
||||
// return root[name].as<boolean>();
|
||||
//}
|
||||
//
|
||||
//int jsonReadInt(String& json, String name) {
|
||||
// DynamicJsonBuffer jsonBuffer;
|
||||
// JsonObject& root = jsonBuffer.parseObject(json);
|
||||
// return root[name];
|
||||
//}
|
||||
//
|
||||
//String jsonWriteStr(String& json, String name, String value) {
|
||||
// DynamicJsonBuffer jsonBuffer;
|
||||
// JsonObject& root = jsonBuffer.parseObject(json);
|
||||
// root[name] = value;
|
||||
// json = "";
|
||||
// root.printTo(json);
|
||||
// return json;
|
||||
//}
|
||||
//
|
||||
//String jsonWriteBool(String& json, String name, boolean value) {
|
||||
// return jsonWriteStr(json, name, value ? "1" : "0");
|
||||
//}
|
||||
//
|
||||
//String jsonWriteInt(String& json, String name, int value) {
|
||||
// DynamicJsonBuffer jsonBuffer;
|
||||
// JsonObject& root = jsonBuffer.parseObject(json);
|
||||
// root[name] = value;
|
||||
// json = "";
|
||||
// root.printTo(json);
|
||||
// return json;
|
||||
//}
|
||||
//
|
||||
//String jsonWriteFloat(String& json, String name, float value) {
|
||||
// DynamicJsonBuffer jsonBuffer;
|
||||
// JsonObject& root = jsonBuffer.parseObject(json);
|
||||
// root[name] = value;
|
||||
// json = "";
|
||||
// root.printTo(json);
|
||||
// return json;
|
||||
//}
|
||||
//
|
||||
//void saveConfig() {
|
||||
// writeFile(String("config.json"), configSetupJson);
|
||||
//}
|
||||
//
|
||||
//void saveStore() {
|
||||
// writeFile(String("store.json"), configStoreJson);
|
||||
//}
|
||||
|
||||
String jsonReadStr(String& json, String name) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonObject& root = jsonBuffer.parseObject(json);
|
||||
return root[name].as<String>();
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
deserializeJson(doc, json);
|
||||
return doc[name].as<String>();
|
||||
}
|
||||
|
||||
boolean jsonReadBool(String& json, String name) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonObject& root = jsonBuffer.parseObject(json);
|
||||
return root[name].as<boolean>();
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
deserializeJson(doc, json);
|
||||
return doc[name].as<bool>();
|
||||
}
|
||||
|
||||
int jsonReadInt(String& json, String name) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonObject& root = jsonBuffer.parseObject(json);
|
||||
return root[name];
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
deserializeJson(doc, json);
|
||||
return doc[name].as<int>();
|
||||
}
|
||||
|
||||
String jsonWriteStr(String& json, String name, String value) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonObject& root = jsonBuffer.parseObject(json);
|
||||
root[name] = value;
|
||||
json = "";
|
||||
root.printTo(json);
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
deserializeJson(doc, json);
|
||||
doc[name] = value;
|
||||
return json;
|
||||
}
|
||||
|
||||
String jsonWriteBool(String& json, String name, boolean value) {
|
||||
return jsonWriteStr(json, name, value ? "1" : "0");
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
deserializeJson(doc, json);
|
||||
doc[name] = value;
|
||||
return json;
|
||||
}
|
||||
|
||||
String jsonWriteInt(String& json, String name, int value) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonObject& root = jsonBuffer.parseObject(json);
|
||||
root[name] = value;
|
||||
json = "";
|
||||
root.printTo(json);
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
deserializeJson(doc, json);
|
||||
doc[name] = value;
|
||||
return json;
|
||||
}
|
||||
|
||||
String jsonWriteFloat(String& json, String name, float value) {
|
||||
DynamicJsonBuffer jsonBuffer;
|
||||
JsonObject& root = jsonBuffer.parseObject(json);
|
||||
root[name] = value;
|
||||
json = "";
|
||||
root.printTo(json);
|
||||
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
||||
deserializeJson(doc, json);
|
||||
doc[name] = value;
|
||||
return json;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user