首页 > 解决方案 > 改造斜杠作为查询

问题描述

我正在尝试从此 api 下载数据:

https://chicken-coop.fr/rest/games/fifa%2019?platform=switch

这是我的接口类

public interface GamesInterface {
    @GET("/rest/games")
    Call<Example> getGamesbyName(@Query("/") String gameName, @Query("platform") String gamePlatform);
}

目前我可以使用微调器更改布局中的平台名称,但我不知道如何更改游戏名称。如何使用斜杠作为@Query("platform")

标签: androidretrofit

解决方案


您可以执行以下操作:

public interface GamesInterface {
    @GET("/rest/games/{gameName}")
    Call<Example> getGamesbyName(@Path("gameName") String gameName, @Query("platform") String gamePlatform);
}

注意@Path注释,它将 a 映射String到 url。您可以通过以下网址阅读更多关于改造的信息:https ://square.github.io/retrofit/


推荐阅读