我想通过url使用参数来进行改造。

Base Url = .../.../...?t=id


“ t”是我的参数。

输出json数据,如下所示:

{
  "id":"1",
  "names":[
     "xxxxxx",
     "yyyyyy"
  ]

}


我该怎么做?你能帮我吗?

最佳答案

您应该声明接口

public interface RestInterface {

    @GET("/fixed_url/{path_param1}_{path_param2}?")
    Result doGetRequest(@Path("path_param1") String from,
                                        @Path("path_param2") String to,
                                        @Query("get_param1") String getParam1,
                                        @Query("get_param2") String getParam2);
}


构建改造对象实例

Retrofit rtft = Retrofit.Builder()
                .baseUrl("http://your_server_url:port")
                .build();


之后,您可以获取接口的实例并进行HTTP REST调用

rtft.create(RestInterface.class).doGetSuggestions(....);

07-24 09:47
查看更多