我有一个json请求/响应对,我正尝试在Android中使用retrofit2。该请求工作正常,并且我得到的响应显示在此处,并通过将日志添加到项目中进行了验证。
前两个字段返回到我的回调OK,但是该“结果”数组始终为空。
发送:
{"jsonrpc": "2.0", "method": "Player.GetActivePlayers", "id": 1}
找回:
{"id":1,"jsonrpc":"2.0","result":[{"playerid":0,"playertype":"internal","type":"audio"}]}
我使用网站jsonschema2pojo生成了以下POJO类
package retroKodi;
import java.util.List;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class player_GetActivePlayersReturn_root {
@SerializedName("id")
@Expose
private int id;
@SerializedName("jsonrpc")
@Expose
private String jsonrpc;
@SerializedName("playerGetActivePlayersResult")
@Expose
private List<player_GetActivePlayersReturn_Result> playerGetActivePlayersResult = null;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getJsonrpc() {
return jsonrpc;
}
public void setJsonrpc(String jsonrpc) {
this.jsonrpc = jsonrpc;
}
public List<player_GetActivePlayersReturn_Result> getPlayerGetActivePlayersResult() {
return playerGetActivePlayersResult;
}
public void setPlayerGetActivePlayersResult(List<player_GetActivePlayersReturn_Result> playerGetActivePlayersResult) {
this.playerGetActivePlayersResult = playerGetActivePlayersResult;
}
}
子列表
package retroKodi;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class player_GetActivePlayersReturn_Result {
@SerializedName("playerid")
@Expose
private int playerid;
@SerializedName("playertype")
@Expose
private String playertype;
@SerializedName("type")
@Expose
private String type;
public int getPlayerid() {
return playerid;
}
public void setPlayerid(int playerid) {
this.playerid = playerid;
}
public String getPlayertype() {
return playertype;
}
public void setPlayertype(String playertype) {
this.playertype = playertype;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
活动电话
kodiRequest_nullParams thisRequest = new kodiRequest_nullParams("2.0", "Player.GetActivePlayers", 15);
(ApiUtilKodi.sendPost().kodiPlayer_GetActivePlayers(thisRequest)).enqueue(new Callback<player_GetActivePlayersReturn_root>() {
@Override
public void onResponse(Call<player_GetActivePlayersReturn_root> call, Response<player_GetActivePlayersReturn_root> response) {
player_GetActivePlayersReturn_root thisResponse = response.body();
String hi = "hi";
//List<player_GetActivePlayersReturn_root.playerGetActivePlayersResult> thisResultList = thisResponse.getPlayerGetActivePlayersResult();
}
@Override
public void onFailure(Call<player_GetActivePlayersReturn_root> call, Throwable t) {
Log.d("response", t.getStackTrace().toString());
}
});
在“ thisResponse”字段中,“ playerGetActivePlayersResult”字段显示为空。
我期望它显示一个数组,或者至少一个我可以分配给列表的指针。
我到底想念什么????我找不到的示例都没有列表作为响应的一部分。它们要么都是简单的1级json模式,要么是假定了一系列简单模式。
答案 0 :(得分:0)
在课程player_GetActivePlayersReturn_root
中进行更改
@SerializedName("playerGetActivePlayersResult")
@Expose
private List<player_GetActivePlayersReturn_Result> playerGetActivePlayersResult = null;
使用
@SerializedName("result")
@Expose
private List<player_GetActivePlayersReturn_Result> result = null;