Android Retrofit 的@Path 不起作用。为什么?

Android Retrofit's @Path don't work. Why?

我有一个应用程序可以从 api 中获取琐事问题并显示。当我使用实际的 link 回答问题时,它有效 (https://trivia.willfry.co.uk/api/questions?categories=movies&limit=16 ) 。但是,当我为类别添加路径时,应用程序不起作用。

这是工作:

@GET("questions?categories=general_knowledge&limit=16")
Call<List<Questions>> general();

然而这是行不通的:

@GET("questions?categories={type}&limit=16")
Call<List<Questions>> getData(@Path("type") String type);

另外,当我从模拟器中删除应用程序,并使用路径包含方法重新安装时,它只运行一次。不是第二次。

categories 不是路径参数,它是一个查询,改为

@GET("questions?limit=16")
Call<List<Questions>> getData(@Query("categories") String categories);

关于你提到的第二个问题,提供的代码中有注释可以从

中找到