how do i write a retrofit query for the array get method?

You can do that in three steps :

1- Use QueryMap instead of Query as follow:

    fun callMatchDetails(
        @QueryMap(encoded = true) map: Map<String, Int>
    ): Call<MatchDetailResponseModel>?

2- Map your competition id list to Map<String,Int> as follow :

        val ids = mutableListOf(123, 134, 156)
        val map = mutableMapOf<String,Int>()
        ids.forEachIndexed { index, id ->
            map["competition_id[$index]"] = id
//mutableMapOf: {competition_id[0]=123, competition_id[1]=134, competition_id[2]=156}

3- Send map to callMatchDetails fun and you will make it look like follow :[0]=123&competition_id[1]=134&competition_id[2]=156

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top