Closed nodoubtman closed 3 years ago
Hi Marc,
Here is to add the new station:
JsonObject station = doc["stations"].createNestedObject();
stations["name"] = "NOUVELLE STATION";
stations["url"] = "https... nouvelle station";
stations["id"] = 285;
Ensure that the JsonDocument
is large enough; otherwise, the new station would be missing.
See also:
Marc, this is a fairly simple problem; I'm surprised you didn't find the answer in the documentation. Please let me know if there is a way I can improve it.
Best regards, Benoit
OK, Benoit. J'avoue que j'ai mal posé ma question, je sais c'est simple de faire un serializeJson avec l'assistant. Merci.
Mais comment je peux ajouter la nouvelle station dans le fichiers spiffs, sans tout chamboulé dans la mémoire.
Merci bien.
J'espère que cette fois-ci la question est bien posée :) Bonne journée.
A+ Marc.
oups!.... j'aurais pas du la fermer
Hi @nodoubtman,
So I guess your question is "how to append an object to a file?".
There are two options, depending on the way you shape the content of the file.
Option 1: The file contains an array (that's your case).
In this case, you must deserialize the file, append the object and serialize back, overriding the file.
Option 2: The file contains line-separated objects (i.e., JSONLines or ndjson).
In this case, you can open the file in append mode and serialize only the new element.
To read all objects of this file, you need to call deserializeJson()
repeatedly.
Best regards, Benoit
PS: added a dedicated page in the documentation
// Write the file file = SPIFFS.open("/southpath.json", "w"); deserializeJson(doc, file); file.close();
tu t'es trompté c'est serializeJson(doc, file); et non deserializejson(doc,file); :)
Et Merci :) Marc.
Merci, Marc, j'ai corrigé la page. N'oublie pas de mettre une étoile pour soutenir ArduinoJson 😉 Bonne chance pour ton projet !
Hello Benoit, I'm Marc from Montreal,QC.
I have a question:
I have a file in spiffs: contains records of radio stations web:
structures:
I just wanted to know if there's a way to insert a new station as it:
Thank you. Marc :)