-1
我有一個非常基本的問題。 我讀儘管LibGDX文檔各地關於JSON和谷歌的答案了幾次,但它仍然簡化版,工作..LibGDX解析標準JSON到一個對象
基本上我從像這樣的服務器,可以作爲拉動JSON:
{"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;
}
當我試圖解析代碼,這是行不通的。我得到null:
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.
結果是什麼結果字符串看起來像 – Barodapride
已更新,它與結果頂部相同。 –
你可以做serverJson.getId()工作嗎? – Barodapride