如何解码Urt参数

时间:2019-08-12 16:30:30

标签: android kotlin

在我的android项目中,我使用Retrofit 2

@GET("/transfers/tunnels")
    fun getTunnelsList(
        @Query("destination[id]") destinationId: String,
        @Query("amuunt") amount: Double,
        @Query("currency") currency: String
    ): Call<List<Tunnel>>

结果如下:

-> GET http://my_ip/transfers/tunnels?destination%5Bid%5D=9eb5fd41-16f8-430c-91b7-a69ad1fd4c89&amuunt=4.0&currency=EUR http/1.1

但是我需要名称为destination[id]的参数

smt是这样的:

-> GET http://my_ip/sends?preferred_agent[id]=12345&amuunt=12.1&currency=USD&receiver[id]=receiverID_guid&destination[id]=destinationId_guid&contract[id]=contractId_guid&is_ready=false 

我该怎么做?

1 个答案:

答案 0 :(得分:1)

您可以将encoded注释的Query参数设置为true。然后它将按预期工作

@GET("/transfers/tunnels")
fun getTunnelsList(
    @Query("destination[id]", encoded = true) destinationId: String,
    @Query("amuunt") amount: Double,
    @Query("currency") currency: String
): Call<List<Tunnel>>