Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在改造中使用@Query?Android Kotlin_Android_Kotlin_Retrofit_Retrofit2 - Fatal编程技术网

如何在改造中使用@Query?Android Kotlin

如何在改造中使用@Query?Android Kotlin,android,kotlin,retrofit,retrofit2,Android,Kotlin,Retrofit,Retrofit2,我目前正在尝试制作一个API接口。我试图通过使用查询操作API URL。到目前为止,我使用的URL是 上面的url我正在尝试更改“查询”,因此我创建了以下界面: @GET("3/search/movie?api_key=${BuildConfig.MOVIE_TOKEN}&language=en-US&") fun getMovies( @Query("query") query: String ): Call<Se

我目前正在尝试制作一个API接口。我试图通过使用查询操作API URL。到目前为止,我使用的URL是

上面的url我正在尝试更改“查询”,因此我创建了以下界面:

@GET("3/search/movie?api_key=${BuildConfig.MOVIE_TOKEN}&language=en-US&")
fun getMovies(
        @Query("query") query: String
): Call<SearchMovieResponse>
@GET(“3/search/movie?api_key=${BuildConfig.movie_TOKEN}&language=en-US&”)
有趣的电影(
@查询(“查询”)查询:字符串
):呼叫
它工作得很好,但是如果URL的情况是这样的呢:

我试图操纵{id}的地方。界面是这样的吗

@GET("3/movie/{id}?api_key=${BuildConfig.MOVIE_TOKEN}")
fun getMovieById(
    @Query("id") id: String
):Call<SearchDetailMovieResponse>
@GET(“3/movie/{id}?api_key=${BuildConfig.movie_TOKEN}”)
有趣的getMovieById(
@查询(“id”)id:字符串
):呼叫

请帮助我了解如何利用注释来修改API URL

您可以使用@Path注释

@GET("3/movie/{id}?api_key=${BuildConfig.MOVIE_TOKEN}")
fun getMovieById(
    @Path("id") id: String
):Call<SearchDetailMovieResponse>
@GET(“3/movie/{id}?api_key=${BuildConfig.movie_TOKEN}”)
有趣的getMovieById(
@路径(“id”)id:字符串
):呼叫
其他信息:

若您在url的中间有一个参数,并且希望给出动态值,那个么使用@Path注释,因为您在url的中间有一个id

e-ghttps://test-api/3/profile. 3是url中间的param,在这种情况下,我们使用@Path

若在url的中间并没有参数,并且希望通过键值对在url的末尾传递参数,那个么最好使用@Query

e-ghttps://test-api/profile?user_id=3 在我们使用@Query的情况下,user_id是键值参数


注意:据我所知,我正在共享。

在以下URL的情况下正确使用
@Query

您需要编写这样的接口

@GET("3/movie/{id}")
fun getMovieById(
    @Path("id") id: String,
    @Query("api_key") apiKey: String = BuildConfig.MOVIE_TOKEN
):Call<SearchDetailMovieResponse>
@GET(“3/movie/{id}”)
有趣的getMovieById(
@路径(“id”)id:String,
@查询(“api密钥”)apiKey:String=BuildConfig.MOVIE\u令牌
):呼叫
有关更多信息,请参阅