使用参数

时间:2019-09-23 15:19:08

标签: java android retrofit2

我想通过url使用参数进行翻新。

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

“ t”是我的参数。

输出json数据如下:

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

}

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

1 个答案:

答案 0 :(得分:1)

您应该声明接口

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(....);