2

I am using retrofit to communicate with a server.

I want to send a 2d array which would be like this

album[0][uuid]:test
album[0][title]:test
album[0][public_text]:aaaaaalhjkl
album[0][private_text]:aaaaaalhjkl
album[1][uuid]:test2
album[1][title]:test2
album[1][public_text]:aaaaaalhjasdfkl
album[1][private_text]:aaaaaalhasdfjkl

in another call when i needed to send only the uuid i tried this and it worked

Call<response> deleteAlbum(@Header("token") String userToken, @Field("album[][uuid]") ArrayList<String> uuid);

and i'm passing an arraylist of strings and it works fine. But here i have a more complex pararigm and i don't know what to do. If I try something like this

Call<response> updateAlbum(@Header("token") String userToken, @Field("album[][uuid]")ArrayList<String> ablumids,@Field("album[][title]")ArrayList<String> title,@Field("album[][public_text]")ArrayList<String> public_text,@Field("album[][private_text]")ArrayList<String> private_text);

the server only reads the first field (uuid) and responds with "there is not enough parameters" . Has anyone any ideas how to solve this?

Thank you

Alex Fragotsis
  • 1,248
  • 18
  • 36

1 Answers1

1

ok so i figured the answer

the call must be

Call<response> updateAlbum(@Header("token") String userToken, @FieldMap Map<String, String>  ablumids);

and pass the data like this

HashMap<String, String> t = new HashMap<String, String>();
    t.put("album[0][uuid]","test");
    t.put("album[0][title]","changeTitleTest2");
    t.put("album[0][public_text]","aaaaaalhjkl");
    t.put("album[0][private_text]","aaaaaalhjkl");

I don't know if it's the best solution but it works

Alex Fragotsis
  • 1,248
  • 18
  • 36
  • hello @Alexander i need a similar kind of work can you please send me the sample code because i need it and i am not understanding how to do that . – S.H Jan 25 '19 at 06:46