java.lang.IllegalStateException:预期为BEGIN_OBJECT但在第1行是STRING

时间:2018-01-16 06:42:22

标签: android retrofit retrofit2

我正在为我的应用程序使用改造。当我尝试访问webservice时,onFailure我收到Expected BEGIN_OBJECT but was STRING at line 1

这是邮递员回复

{
    "status": true,
    "message": "order status updated"
} 

Oncreate

 Gson gson = new GsonBuilder()
                    .setLenient()
                    .create();
    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();

            retrofit = new Retrofit.Builder()
                    .baseUrl("https://example.com/sample/")
                    .client(client)
                    .addConverterFactory(GsonConverterFactory.create(gson))
                    .build();
token="eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9";
id_order= 288;
status="process";
update();

方法

public void update(){
        WebserviceAPI apiService =retrofit.create(WebserviceAPI.class);
        Call<UpdateOrderResponse> call = apiService.updateOrder("pickorder",token,id_order,status);
        call.enqueue(new Callback<UpdateOrderResponse>() {
            @Override
            public void onResponse(Call<UpdateOrderResponse> call, Response<UpdateOrderResponse> response) {

                UpdateOrderResponse result = response.body();
                Log.d("orderstatus", "body: "+result);
                returnstatus=result.isStatus();
                msg= result.getMessage();

                if(returnstatus){
                    Log.d("orderstatus","status ok");
                }else{
                    Log.d("orderstatus","status not ok");
                }
            }

            @Override
            public void onFailure(Call<UpdateOrderResponse> call, Throwable t) {
                Log.d("proceedFail",""+t.getMessage());

            }
        });

    }

响应类

public class UpdateOrderResponse {

    boolean status;
    String message;

    public boolean isStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

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

0 个答案:

没有答案