ArduinoJSON: Beheben von 1 oder 0 statt true/false bei der Ausgabe
English
Deutsch
arduinojson_boolean_issue.cpp
volatile bool value = true;
DynamicJsonDocument json(1024);
json["ok"] = value;
serializeJson(json, Serial);Dies gibt {"ok": 1} statt {"ok": true} aus, da value als volatile deklariert ist (es funktioniert mit nur bool value, es funktioniert nicht mit volatile bool value).
Um {"ok": true} zu erzwingen, wandeln Sie den Wert einfach in bool um:
arduinojson_boolean_cast.cpp
json["ok"] = (bool)value;Vollständiges Beispiel
arduinojson_full_example.cpp
volatile bool value = true;
DynamicJsonDocument json(1024);
json["ok"] = (bool)value;
serializeJson(json, Serial);Check out similar posts by category:
Arduino, Embedded, PlatformIO
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow