You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've finally managed to find an issue in my code: the content of the buffer for file operation isn't copied into DynamicJsonBuffer, so its memory becomes invalid when execution goes out of scope (I've adjusted the initial code).
I've also found the sample how to parse JSON from SPIFFS, which makes temporary buffer redundant + shorter code.
The text was updated successfully, but these errors were encountered:
Anton-V-K
changed the title
JSON gets corrupted when reading from file and modifying it
JSON gets corrupted when creating it from a temporary buffer
Oct 24, 2017
Anton-V-K
changed the title
JSON gets corrupted when creating it from a temporary buffer
JSON gets corrupted when created from a temporary buffer
Oct 24, 2017
As I understand, you found the solution by yourself. 👍
Since the input of parseObject() was a char*, the parser assumed it to be persistent; and therefore stored a pointer to a temporary buffer.
Now, as you found, you can avoid this problem by just calling parseObject(file).
In that case, the parser knows that the input is volatile and will make the copy in the JsonBuffer.
Well, I guess the issue may be closed. Though I think the interface of DynamicJsonBuffer is somewhat confusing with overloaded method parseObject - the specifics of handling const/non-const buffer is easily overlooked...
When JSON is read from file (SPIFFS is used) into
DynamicJsonBuffer
and some values are modified, it gets corrupted.Sample code for testing:
The output when ran 1st time (OK):
The output when ran 2nd time (JSON is corrupted):
Expected output when ran 2nd time:
Target platform: ESP8266 (WeMos D1 R2)
IDE: Arduino IDE 1.6.13
LIB version: 5.11.2
I've finally managed to find an issue in my code: the content of the buffer for file operation isn't copied into
DynamicJsonBuffer
, so its memory becomes invalid when execution goes out of scope (I've adjusted the initial code).I've also found the sample how to parse JSON from SPIFFS, which makes temporary buffer redundant + shorter code.
The text was updated successfully, but these errors were encountered: