我的回复中的错误使用改造的呼叫列表

时间:2018-06-17 17:12:01

标签: android arrays json retrofit2

我试图获得一份球员名单。我收到了Call>的回复3个玩家但是采用了古怪的格式。 我不知道我的错误在哪里,我搜索了5个小时没有结果。

ApiClient.class:

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.sat.sat.Method.FMethod;
import java.io.IOException;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Haytham on 2018-05-15.
 */

public class ApiClient {
    public static final String Base_Url = "https://www.url.com/";
    public  static Retrofit getRetrofit() {
        Gson gson = new GsonBuilder()
                .setDateFormat("yyyy-MM-dd'T'HH:mm:ss")
                .create();
            Retrofit retrofit = new Retrofit
                    .Builder()
                    .baseUrl(Base_Url)
                .addConverterFactory(GsonConverterFactory.create(gson)).build();
            return retrofit;
        }}

接口:

    @GET("api/coach/player_list")
 Call<List<PlayerListResponse>> getPlayerList (@Query("token") String Token);

MyActivity:

    ***ApiInterface service = ApiClient.getRetrofit().create(ApiInterface.class);
    Call <List<PlayerListResponse>> PlayerListCall = service.getPlayerList(FMethod.TokenFC);
    PlayerListCall.enqueue(new Callback<List<PlayerListResponse>>() {
        @Override
        public void onResponse(Call<List<PlayerListResponse>> call, Response<List<PlayerListResponse>> response) {
            int  StatusCode=response.code();
            if (StatusCode==200) {
                Log.d("PlayerList", "onResponse: "+StatusCode+ response.body().toString());
            }
            if (StatusCode==401) {
                Toast.makeText(Coach_list_player.this, "Token"+FMethod.TokenFC, Toast.LENGTH_SHORT).show();
            }
        }***

我的POJO:

    package com.sweatacademytech.sweatacademy.Pojo;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

public class PlayerListResponse {
    @SerializedName("id")
    @Expose
    private Integer id;
    @SerializedName("fname")
    @Expose
    private String fname;
    @SerializedName("lname")
    @Expose
    private String lname;
    @SerializedName("email")
    @Expose
    private String email;
    @SerializedName("date_assigned")
    @Expose
    private String dateAssigned;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getFname() {
        return fname;
    }

    public void setFname(String fname) {
        this.fname = fname;
    }

    public String getLname() {
        return lname;
    }

    public void setLname(String lname) {
        this.lname = lname;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getDateAssigned() {
        return dateAssigned;
    }

    public void setDateAssigned(String dateAssigned) {
        this.dateAssigned = dateAssigned;
    }
}

我在我的log.debug中找到了:06-17 16:57:23.007 200它的Okey [com.sat.sweatacademy.Pojo.PlayerListResponse@2077dfd,com.sat.sat.Pojo.PlayerListResponse@441eaf2,com.sat.sat.Pojo.PlayerListResponse@ed2f543]

1 个答案:

答案 0 :(得分:2)

没有错误

Call<List<PlayerListResponse>> getPlayerList (@Query("token") String Token);

您的方法返回List PlayerList ...并且日志显示正好...

com.sweatacademytech.sweatacademy.Pojo.PlayerListResponse

如果您感到担心,因为您没有看到日志中的实际玩家字段是因为您没有覆盖toString(),但这不是错误,只是误解了您...

顺便说一句,你应该更好地命名你的课程