0
Steot APIからデータを取得するためにretorfitを使用していますが、レスポンスがnullですが、ログに正しいJSON応答が表示されます。更新のレスポンスがnull
これはAPIからJSONです:
{
"response": {
"players": [
{
"steamid": "76561197960435530",
"communityvisibilitystate": 3,
"profilestate": 1,
"personaname": "Robin",
"lastlogoff": 1508048552,
"profileurl": "http://steamcommunity.com/id/robinwalker/",
"avatar": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/f1/f1dd60a188883caf82d0cbfccfe6aba0af1732d4.jpg",
"avatarmedium": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/f1/f1dd60a188883caf82d0cbfccfe6aba0af1732d4_medium.jpg",
"avatarfull": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/f1/f1dd60a188883caf82d0cbfccfe6aba0af1732d4_full.jpg",
"personastate": 0,
"realname": "Robin Walker",
"primaryclanid": "103582791429521412",
"timecreated": 1063407589,
"personastateflags": 0,
"loccountrycode": "US",
"locstatecode": "WA",
"loccityid": 3961
}
]
}
}
これらは私のPOJOです:
public class Response {
@SerializedName("players")
private List<Player> mPlayers;
public List<Player> getPlayers() {
return mPlayers;
}
public void setPlayers(List<Player> players) {
mPlayers = players;
}
}
public class Player {
@SerializedName("avatar")
private String mAvatar;
@SerializedName("avatarfull")
private String mAvatarfull;
@SerializedName("avatarmedium")
private String mAvatarmedium;
@SerializedName("communityvisibilitystate")
private Long mCommunityvisibilitystate;
@SerializedName("lastlogoff")
private Long mLastlogoff;
@SerializedName("loccityid")
private Long mLoccityid;
@SerializedName("loccountrycode")
private String mLoccountrycode;
@SerializedName("locstatecode")
private String mLocstatecode;
@SerializedName("personaname")
private String mPersonaname;
@SerializedName("personastate")
private Long mPersonastate;
@SerializedName("personastateflags")
private Long mPersonastateflags;
@SerializedName("primaryclanid")
private String mPrimaryclanid;
@SerializedName("profilestate")
private Long mProfilestate;
@SerializedName("profileurl")
private String mProfileurl;
@SerializedName("realname")
private String mRealname;
@SerializedName("response")
private Response mResponse;
@SerializedName("steamid")
private String mSteamid;
@SerializedName("timecreated")
private Long mTimecreated;
public String getAvatar() {
return mAvatar;
}
public void setAvatar(String avatar) {
mAvatar = avatar;
}
public String getAvatarfull() {
return mAvatarfull;
}
public void setAvatarfull(String avatarfull) {
mAvatarfull = avatarfull;
}
public String getAvatarmedium() {
return mAvatarmedium;
}
public void setAvatarmedium(String avatarmedium) {
mAvatarmedium = avatarmedium;
}
public Long getCommunityvisibilitystate() {
return mCommunityvisibilitystate;
}
public void setCommunityvisibilitystate(Long communityvisibilitystate) {
mCommunityvisibilitystate = communityvisibilitystate;
}
public Long getLastlogoff() {
return mLastlogoff;
}
public void setLastlogoff(Long lastlogoff) {
mLastlogoff = lastlogoff;
}
public Long getLoccityid() {
return mLoccityid;
}
public void setLoccityid(Long loccityid) {
mLoccityid = loccityid;
}
public String getLoccountrycode() {
return mLoccountrycode;
}
public void setLoccountrycode(String loccountrycode) {
mLoccountrycode = loccountrycode;
}
public String getLocstatecode() {
return mLocstatecode;
}
public void setLocstatecode(String locstatecode) {
mLocstatecode = locstatecode;
}
public String getPersonaname() {
return mPersonaname;
}
public void setPersonaname(String personaname) {
mPersonaname = personaname;
}
public Long getPersonastate() {
return mPersonastate;
}
public void setPersonastate(Long personastate) {
mPersonastate = personastate;
}
public Long getPersonastateflags() {
return mPersonastateflags;
}
public void setPersonastateflags(Long personastateflags) {
mPersonastateflags = personastateflags;
}
public String getPrimaryclanid() {
return mPrimaryclanid;
}
public void setPrimaryclanid(String primaryclanid) {
mPrimaryclanid = primaryclanid;
}
public Long getProfilestate() {
return mProfilestate;
}
public void setProfilestate(Long profilestate) {
mProfilestate = profilestate;
}
public String getProfileurl() {
return mProfileurl;
}
public void setProfileurl(String profileurl) {
mProfileurl = profileurl;
}
public String getRealname() {
return mRealname;
}
public void setRealname(String realname) {
mRealname = realname;
}
public Response getResponse() {
return mResponse;
}
public void setResponse(Response response) {
mResponse = response;
}
public String getSteamid() {
return mSteamid;
}
public void setSteamid(String steamid) {
mSteamid = steamid;
}
public Long getTimecreated() {
return mTimecreated;
}
public void setTimecreated(Long timecreated) {
mTimecreated = timecreated;
}
}
そしてここでは、私の要求です:
call.enqueue(new Callback<Response>() {
@Override
public void onResponse(Call<Response> call, Response<Response> response) {
Log.d(TAG, "onResponse: " + response.body().getPlayers());
}
@Override
public void onFailure(Call<com.example.konem.pubgstat.Models.Response> call, Throwable t) {
}
});
私はいくつかの回避策を試してみましたが、私はそれが仕事を得ることができない、response.body.getPlayers()は常にnullを返します。
@SerializedName("response")
@Expose
private Response_ response;
public Response_ getResponse() {
return response;
}
public void setResponse(Response_ response) {
this.response = response;
}
public class Response_ {
@SerializedName("players")
@Expose
private List<Player> players = null;
public List<Player> getPlayers() {
return players;
}
public void setPlayers(List<Player> players) {
this.players = players;
}
}
そして選手クラス:あなたの助け:)
お願いします。コールと応答を返すときに、ログをコピーして貼り付けることはできますか? おそらくあなたのデータモデルは正しいですが、実際にはヌル応答を受け取ります。 – DaCrAn
私のデータモデルが間違っていた、私は1つのクラスを逃した、応答は常に良かった:) –