Add an array as request parameter with Retrofit 2

后端 未结 7 709
故里飘歌
故里飘歌 2020-12-10 11:04

I\'m looking for way to add an int array (e.g [0,1,3,5]) as parameter in a GET request with retrofit 2. Then, the generated url should be like this : http:/

7条回答
  •  囚心锁ツ
    2020-12-10 12:04

    Well this did the trick for me

    Step 1 :

    In StateServce.kt

    @GET("states/v1")
    fun getStatesByCoordinates(@Query("coordinates", encoded = true) coordinates: String) : Call>>
    

    Step 2

    While calling from repository

    val mCoordinate : List = [22.333, 22.22]
    mStateService?.getStatesByCoordinates(mCoordinate.toString().replace(" ", ""))!!
    

提交回复
热议问题