I’ve been looking into using JSON as a way to store data for a puzzle game I’m working on.
My JSON data looks like this:
{
"paintingsData": [
{
"hashmap_key": "gulf",
"painter": "Josephus Augustus Knip",
"title": "The Gulf of Naples with the Island of Ischia in the Distance",
"year": "c. 1818",
"filepath_painting": "paintings/gulf_of_naples1280x785_q5.jpg",
"filepath_button": "select_screen/gulf_of_naples.png",
"button_text": "The Gulf of Naples",
"puzzle_state": "play"
},
...
... ec. times ~50
Now i figured out how to get all the data out of my json file and create an ArrayList of PaintingData objects that I can use throughout my game.
That’s all good, but what I’m looking to get a little help with are 2 things. (I have been looking at some tutorials and at the LibGDX wiki but so far haven’t figured it out):
1. How do I change data in my JSON file. For example if the user completes a puzzle I want to change the “puzzle_state” from “play” to “solved”.
2. How do I store my changed data from my changed json file on Android. I know I can save data to a file something like:
String string= json.prettyPrint(arrayList-that-contaise-the-JSON-data);
FileHandle file = Gdx.files.external("jsontest.json");
file.writeString(string, false);
This will create a jsontest.json in the root of my libgdx desktop project, but that liekly won’t work on an Android Device.
Having read: http://developer.android.com/training/basics/data-storage/files.html it looks to me that I want to save the file on InternalStorage, but I have no idea on how to do that yet.
Any help?