首页 > 解决方案 > 未找到改造注释。@GET 调用中的(参数 #2)

问题描述

我正在尝试从电影 api 中获取一些数据。我尝试像往常一样进行改造,但第二个参数出现错误。这可能是因为字符串参数视频(在生成 Json 文件的链接中)它不是“变量”参数,所以它可能无法识别调用。

服务:

public interface Service {

@GET("/3/movies/{id}")
Call<TrailerResponse> getVideos (
        @Path("id") int id,
        String videos,
        @Query("api_key") String apiKey,
        @Query("language") String language
);
}

加载(我认为指定的 getVideos 中的变量并不重要)

    public static List<Videos> load() {
    Service apiService = Client.getClient().create(Service.class);
    Call<TrailerResponse> call;
    call = apiService.getVideos(ID, VIDEOS, API_KEY, LANGUAGE);
    if(call == null){
        return null;
    }

标签: androidjsonapiandroid-studioretrofit2

解决方案


看起来您需要删除videos参数,并将其添加到 url 的路径中。

此外,如果您查看文档,路径应该是movie而不是movies,并且 ID 参数应该是movie_id而不是id

public interface Service {

@GET("/3/movie/{id}/videos")
Call<TrailerResponse> getVideos (
        @Path("movie_id") int id,
        @Query("api_key") String apiKey,
        @Query("language") String language
);
}

推荐阅读