我有一些关于改造 2 的问题

如何修复预期的 BEGIN_ARRAY 但在改造 2 中是 BEGIN_OBJECT

我不知道修复它

我怎么了?

我的 json 是

{
    "result": true,
    "message": "success",
    "data": [
        {
            "id": "10",
            "type_name": "pppppp"
        },
        {
            "id_mt": "11",
            "type_name": "aaaaaa"
        }
    ]
}

我的模型类是
public class MessageFastModel {
    private boolean result;
    private String message;

    private List<DataBean> data;

    public boolean isResult() {
        return result;
    }

    public void setResult(boolean result) {
        this.result = result;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public List<DataBean> getData() {
        return data;
    }

    public void setData(List<DataBean> data) {
        this.data = data;
    }

    public static class DataBean {
        private String id;
        private String type_name;

        public String getId() {
            return id;
        }

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

        public String getType_name() {
            return type_name;
        }

        public void setType_name(String type_name) {
            this.type_name = type_name;
        }
    }
}

我的代码是
 @FormUrlEncoded
 @POST("api/message_type")
 Call<MessageFastModel> listMessageFast(@Field("token") String token);


Call<MessageFastModel> dddddCall = ooooo.listMessageFast(Preferences.getToken());
                        dddddCall.enqueue(new Callback<MessageFastModel>() {
                            @Override
                            public void onResponse(Call<MessageFastModel> call, Response<MessageFastModel> response) {
                                if (response.isSuccessful()) {
                                    Log.d("ddd", "onResponse: " + response.body().getData().size());
                                }
                            }

                            @Override
                            public void onFailure(Call<MessageFastModel> call, Throwable t) {
                                Log.e("ddd", "onFailure: " + t.getMessage());
                            }
                        });

但我的错误是



什么问题 ?谢谢!

最佳答案

  @GET("photos")
Call<Model> savePhoto();

并像这样调用您的改造方法 >>>
 Call<Model> call = apiService.savePhoto();

        call.enqueue(new retrofit2.Callback<Model>() {
            @Override
            public void onResponse(Call<Model> call, retrofit2.Response<Model> response) {
                int statusCode = response.code();
                try {
                    Model model;
                   // Log.w("resedatasync", new Gson().toJson(response));
                    model= response.body();

并像这样创建您的模型类
public class Model{

@SerializedName("ArrayName")
 public List<DataBean > arraylist= new ArrayList<>();

@SerializedName("message")
private String message;

public class DataBean {

    @SerializedName("id")
     private String id;

    @SerializedName("typename")
     private String typename;

    @SerializedName("typename")
    public void settypename(String typename) {
        this.typename= typename;
    }

}

}

关于java - 预期为 BEGIN_ARRAY 但为 BEGIN_OBJECT 改造2,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47346823/

10-10 23:55