I have a big JSON config file on an SD on my Arduino
"general": {
"dhcp": true,
"macAddress": [500,500,500,500,500,500],
"destinationIP": [500,500,500,500],
"serverHostname": null,
"interval": 5,
"commaDecimalSeperator": true,
"baudrate": 115200
},
"networking": {
"ipAddress": [500,500,500,500],
"subnetMask": [500,500,500,500],
"gateway": [500,500,500,500]
},
"data": {
"csvHeader": "bla;bla;bla",
"csvSeperator": ";",
"filename": "data.csv"
},
and so on...
is there a way of turning JSON objects into structs or something like that in Arduino? Because at the moment a lot of my code is just assigning JSON objects to variables with the same name
My current code:
struct General {
bool dhcp;
byte mac[6];
int destinationIP[4];
String serverHostname;
int interval;
bool commaDecimalSeperator;
long baudrate;
};
void setup() {
JsonObject general_1 = doc["general"];
general.dhcp = general_1["dhcp"];
general.interval = general_1["interval"];
general.commaDecimalSeperator = general_1["commaDecimalSeperator"];
general.baudrate = general_1["baudrate"];
}
...
What I would like:
loadJSONToStructs(doc)
Serial.print(General.dhcp)
question from:
https://stackoverflow.com/questions/65906971/create-struct-from-json-object-in-c-arduino 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…