【发布时间】:2019-09-16 11:22:16
【问题描述】:
对 API 的示例请求是这样的
https://api.example.com/api/3.0/song/{song_id}.json?apikey={your_api_key}
所以,在我的活动中
//retrofit
final Retrofit retrofit = new Retrofit.Builder()
.baseUrl(C.BASE_URL_DETAIL) // "https://api.example.com/api/3.0/song/"
.addConverterFactory(GsonConverterFactory.create())
.build();
SongInterface request = retrofit.create(SongInterface.class);
//call
Call<SongObject> call =request.getDetails(C.MY_API_KEY);
我的歌曲 id = 10973 界面
@GET("10973.json?")
Call<SongObject> getDetails(
@Query("apikey") String key
);
它工作得很好,我收到了预期的数据。但是,我不知道如何用另一个 id 调用另一首歌曲并重用代码。我可以以某种方式将 ID 添加为查询参数吗? (API 似乎没有设置为允许这样做)。如何将字符串动态更新到@GET 中的接口。我的尝试都以错误告终。
【问题讨论】: