-2

I want to add duplicate key paramaters in retrofit. For example: https://www.google.co.in/?gfe_rd=cr&ei=1&ei=2&ei=3&ei=4&ej=1&ej=2&ej=3&ek=1&ek=2&ek=3&el=1&el=2&el=3.

These key parameters are adding dynamically. How to resolve this problem. Please Help. Thanks in advance.

Manoj Kumar
  • 307
  • 2
  • 7
  • 13
  • 2
    Possible duplicate of [Using Retrofit in Android](http://stackoverflow.com/questions/26500036/using-retrofit-in-android) – Nevres May 20 '17 at 10:34

1 Answers1

0

You can use ArrayList like;

Call<YourResponseType> yourFunc(@Query("gfe_rd") String value, @Query("ei") ArrayList<String> eiValues, @Query("ej") ArrayList<String> eJvalues,...);

it will work like;

http://yourUrl.com/gfe_rd=cr&ei=1&ei=2...

or you can do it with using path and a for.

String path = "/?";
for (int i = 0; i < yourQueryCount ; i ++ ){
    if (i == 0)
        path += "gfe_rd" + yourValue;
    else if ( i < 5)
        path += "ei=" + yourDynamicValueArrayForEi[i];
    else if ( i < 7)
        path += "ej=" + yourDynamicValueArrayForEj[i];
    .
    .
    .

    if (i < yourQueryCount-1)
     path += "&";
}

and give that path to your retrofit function;

@GET("{yourPath}")
Call<YourResponseType> yourFunc(@Path("yourPath") String path);
AtaerCaner
  • 691
  • 7
  • 12