Java LibGDX将标准json解析为对象
我有一个非常基本的问题。 我读了几遍关于JSON和Google的LibGDX文档,想找到答案,但仍然不起作用 基本上,我是从一个服务器中提取json,比如:Java LibGDX将标准json解析为对象,java,json,libgdx,Java,Json,Libgdx,我有一个非常基本的问题。 我读了几遍关于JSON和Google的LibGDX文档,想找到答案,但仍然不起作用 基本上,我是从一个服务器中提取json,比如: {"id":1,"facebook_id":"23432232","json":"{\"json\":\"test\"}"} 我有一门课是这样的: public class ServerJson { public static final String NAME = "ServerJson"; private int id; priva
{"id":1,"facebook_id":"23432232","json":"{\"json\":\"test\"}"}
我有一门课是这样的:
public class ServerJson
{
public static final String NAME = "ServerJson";
private int id;
private String facebookID;
private String json;
public ServerJson(){}
public ServerJson(int id, String facebookID, String json)
{
this.id = id;
this.facebookID = facebookID;
this.json = json;
}
public int getId() {
return id;
}
public String getFacebookID() {
return facebookID;
}
public String getJson() {
return json;
}
当我试图解析代码时,它不起作用。我得到空值:
String resultString = httpResponse.getResultAsString(); //{"id":1,"facebook_id":"23432232","json":"{\"json\":\"test\"}"}
Json json = new Json();
ServerJson serverJson = json.fromJson(ServerJson.class, resultString);
log(serverJson.getFacebookID()); //<< Is null.
String resultString=httpResponse.getResultAsString()//{“id”:1,“facebook\u id”:“2343232”,“json”:“{\“json\”:\“test\”}”
Json=newJSON();
ServerJson ServerJson=json.fromJson(ServerJson.class,resultString);
日志(serverJson.getFacebookID())// 确保对象类的字段与json对象的字段匹配。resultString看起来像什么更新的,它与up-top的结果是一样的。你可以执行serverJson.getId()吗?谢谢,我一整天都在努力解决这个问题。就像字段不匹配一样简单!!!