I am working in Unity, on my first project. I am working on a turn-based RPG, and I am having a hard time figuring out my back end.
I'm currently using JSON files to store my data, which are then converted into objects and processed in C#. So far so good, but I have reached a road block when trying to save data back into a JSON file.
For example, lets say I have a character file such as: [{"name":"John", "CurrentHP": 100, "MaxHP": 100},{"name":"Paul", "CurrentHP": 200, "MaxHP": 200}]
. After a combat, John loses 30 hp. How do I save this data back to that JSON file, so it reads as [{"name":"John", "CurrentHP": 70, "MaxHP": 100},{"name":"Paul", "CurrentHP": 200, "MaxHP": 200}]
?
The tutorials I've watched all talk about serializing the object back into a JSON file, but this would involve deleting the whole file and creating a new one with the new information. This sounds like a very ineffective approach, especially for some large 'tables' in my game. There needs to be a way to update just one attribute from one of the IDs in a given JSON file.
How do I efficiently update individual JSON rows?