【问题标题】:No Retrofit annotation found. (parameter #2) in @GET call未找到改造注释。 @GET 调用中的(参数 #2)
【发布时间】:2020-08-11 07:59:42
【问题描述】:

我正在尝试从电影 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;
    }

【问题讨论】:

    标签: android json api android-studio retrofit2


    【解决方案1】:

    看来你需要去掉videos参数,把它添加到url的路径中。

    另外,如果你看the documentation,路径应该是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
    );
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-03
      • 2015-04-06
      • 2022-07-31
      • 1970-01-01
      • 1970-01-01
      • 2017-08-26
      • 1970-01-01
      相关资源
      最近更新 更多