我尝试将来自NewOrderRequest(pojo)类的数据放入参数中:
@Query("params") NewOrderRequest params
但我得到这个结果:
resultQueryString:参数com.example.city.Model.NewOrderRequest@f45c8ad
预期结果:
resultQueryString:参数+911
资料设定:
NewOrderRequest newOrderRequest = new NewOrderRequest();
newOrderRequest.setPhone("+911");
NetworkService.getInstance()
.service()
.newOrder(newOrderRequest)
请求:
@Headers({"Accept:application/json", "Content-Type:application/json;"})
@POST("RemoteCall?method=Taxi.WebAPI.NewOrder")
Call<RegResponse>newOrder(@Header("Cookie") String setCookie,@Query("params") NewOrderRequest params);
请告诉我如何将手机传递给参数?
最佳答案
您要在@Query
参数中发送对象,只有@Body
接受该对象作为其参数。您想要的是将Object转换为JsonObject。我假设您正在使用Gson库。
NewOrderRequest newOrderRequest = new NewOrderRequest();
newOrderRequest.setPhone("+911");
NetworkService.getInstance()
.service()
.newOrder(new Gson().toJson(newOrderRequest))