I want to be able to save my game, so I packed the information into a object(class) named GameController. How can I convert the information written in the JSON file back into my GameController object?
My saving code:
public static void Save(GameController controller) {
JSONObject obj = new JSONObject();
obj.put("controller", controller);
try(FileWriter fileWriter = new FileWriter("saved.json")) {
fileWriter.write(obj.toString());
fileWriter.flush();;
}
catch(IOException e) { e.printStackTrace(); }
}
Upd: Friends online kindly suggested a related problem, but I don't think it did solve my problem. The problem of mine is my JSON file turned out to be like this:
{"controller":xyz.chengzi.aeroplanechess.controller.GameController@5c30107a}
And this JSON file doesn't allow phrasing, so I don't even know how to turn it into a JSON object. Does anybody know how to deal with this or did I save my file in a wrong way?