我正在为我的应用程序使用改造。当我尝试访问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;
}
}