JsonDocument is not maintaining char[] data in nested scope
Created by: kawinie
StaticJsonDocument<200> doc;
JsonArray array = doc.to<JsonArray>();
{
JsonObject obj = array.createNestedObject();
char text[] = "Panda Cubs;";
obj["text"].set(text);
}
serializeJsonPretty(array, Serial);
The above code incorrectly outputs
[
{
"text": "(sometimes garbage, other times empty)"
}
]
Adding an explicit (char *) cast to "text" outputs a correct result.
StaticJsonDocument<200> doc;
JsonArray array = doc.to<JsonArray>();
{
JsonObject obj = array.createNestedObject();
char text[] = "Panda Cubs;";
obj["text"].set((char *)text);
}
serializeJsonPretty(array, Serial);
[
{
"text": "Panda Cubs"
}
]
Seems like the problem is that JsonDocument thinks char[]
is const char *
, in which case the document simply just copy over the pointer.