Json json = new Json(); json.setTypeName(null); json.setUsePrototypes(false); json.setIgnoreUnknownFields(true); json.setOutputType(OutputType.json); // I'm using your file as a String here, but you can supply the file as well Data data = json.fromJson(Data.class, "{\"table\": [{\"id\": 1},{\"id\": 2},{\"id\": 3},{\"id\": 4}]}");
/*...*/ Json json = new Json(); String jsonStr = /* JSON here */ jsonStr = jsonStr.replace("\"3h\"", "\"_3h\""); JSONWrapper jsonWrapper = json.fromJson(JSONWrapper.class, jsonStr); /*...*/
PlayerScore score = new PlayerScore("Player1", 1537443); // The Highscore of the Player1 Json json = new Json(); String score = json.toJson(score);
Json json = new Json(); ArrayList<HexTile> hexTiles = json.fromJson(ArrayList.class, Gdx.files.internal("myJsonFile.json"));
Hashtable<String, String> hashTable = new Hashtable<String, String>(); Json json = new Json(); hashTable.put("test", json.toJson(ints) ); //here you are serializing the array ... //putting the map into preferences String serializedInts = Gdx.app.getPreferences("preferences").getString("test"); int[] deserializedInts = json.fromJson(int[].class, serializedInts); //you need to pass the class type - be aware of it!
FileHandle scores = Gdx.files.local("Score"); winstringread = scores.readString(winstring); Json json = new Json(); GameResults results = json.fromJson(GameResults, winstringread);
FileHandle file = Gdx.files.local("scores.json"); String scores = file.readString(); Json json = new Json(); PlayerScore score = json.fromJson(PlayerScore.class, scores);
Json json = new Json(); JsonValue root = new JsonReader().parse(Gdx.files.internal("path/to/your/file.json")); JsonValue extra = root.get("extra"); //Replace 'extra' with whatever your object is called. MyObject myObj = json.fromJson(MyObject.class, extra.toString());
GameResults results = new GameResults(); results.setWins(winstring); Json json = new Json(); FileHandle scores = Gdx.files.local("Score"); scores.writeString(json.toJson(results), false);
FloatArray levels = new FloatArray(); levels.add(5993); levels.add(5995); ... Preferences p = Gdx.app.getPreferences("SETTINGS"); Json json = new Json(); String levelsJson = json.toJson(FloatArray.class, levels); p.putString("levels", levelsJson);
Json json = new Json(); json.setTypeName(null); json.setUsePrototypes(false); json.setIgnoreUnknownFields(true); json.setOutputType(OutputType.json); json.toJson(config, GameConfig.class);
public void load() { //instead of this line: //buttons = new Array<Button>(); Json json = new Json(); json.setTypeName(null); json.setUsePrototypes(false); json.setIgnoreUnknownFields(true); json.setOutputType(JsonWriter.OutputType.json); // set buttons here: buttons = json.fromJson(Data.class, Gdx.files.internal("buttons.json")); }
final Json json = new Json(); final String infiniteLoopOrStackOverflowErrorHappensHere = json.toJson(state.toGameSaveState()); state = json.fromJson(GameSaveState.class, infiniteLoopOrStackOverflowErrorHappensHere).toGameState();