I've used ArduinoJson with the Photon 2 successfully before, but today I ran into a weird bug where JsonObject
truncates string literals to just one character (when the string literals are stored as keys or values).
Here is the code:
JsonDocument doc;
String jsonString;
JsonObject obj0 = doc.createNestedObject();
obj0["key"] = "Temperature (F)";
obj0["value"] = random(60, 100);
serializeJson(doc, jsonString);
Serial.println(jsonString);
delay(5000);
and here is the output:
[{"k":"T","v":84}]
However, if I change the code to replace the string literals with string variables, it works correclty. For example, with this code
String strKey = "key";
String strValue = "value";
String strTemp = "Temperature (F)";
obj0[strKey] = strTemp;
obj0[strValue] = random(60, 100);
I get the expected output
[{"key":"Temperature (F)","value":76}]
Any one have any idea why this is happening, or a better workaround?
Thanks!