c# - Adding new values to JSON (Unity3d) -


i need little help. i'm using json save of game progress values , working except i'm facing 1 issue. when try save new values overrides old ones don't want override old values wanna keep them , add new ones. can provide little help? i'm using litjson, here code:

 savedships savedships = new savedships(shipscount);      jsondata data = jsonmapper.tojson(savedships);      file.writealltext(application.datapath + "/ships.json", data.tostring()); 

i tried loading old values , adding new ones this:

string fromjson = file.readalltext(application.datapath + "/ships.json"); data = jsonmapper.toobject(fromjson); data.add(new savedships(shipscount)); file.writealltext(application.datapath + "/ships.json", data.tostring()); 

but got argumentexception: unable wrap given object jsondata. thanks!

use file.appendtext() instead of writealltext().

https://msdn.microsoft.com/en-us/library/system.io.file.appendtext(v=vs.110).aspx

this should add end of file instead of overwriting it.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -