我查看了大多数关于在 Libgdx 中使用 Json 的在线教程,这看起来非常简单。但是,出于某种原因,json.toJson() 不断返回一个双元胞数组,第一个包含 {,第二个包含 }。 我的代码很简单:
public class GameConfig {
public int screenWidth;
public int screenHeight;
public GameConfig() {
screenWidth = 800;
screenHeight = 600;
}
}
然后
String configAsText = json.toJson(zzz);//configAsText.value equals [0] = { and [1] = }
String configAsText = json.toJson(config, GameConfig.class);//nor this one
有什么想法吗?
最佳答案
试试下面的代码。我是这样使用它的,在大多数情况下,我不需要任何自定义序列化程序,因为 libgdx 用于序列化的内部反射。
Json json = new Json();
json.setTypeName(null);
json.setUsePrototypes(false);
json.setIgnoreUnknownFields(true);
json.setOutputType(OutputType.json);
json.toJson(config, GameConfig.class);
关于java - Libgdx,JSON : Json. tojson(object) 不断返回 {},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23181623/