0

Here is what i want to send in a post request with retrofit any idea?

"quiz_data" : [ ['question_id' => 1, 'option_id' => 2], ['question_id' => 2, 'option_id' => 3], ['question_id' => 3, 'option_id' => 2] ] 

It has to be dynamic as I don't know how many quiz questions will be added from the admin.

ALI REHMAN
  • 23
  • 9

2 Answers2

1

I think you can create a Call with a Map object that has the values that you need.


@POST("{endpoint}")
Call<Void> sendData(@Body Map<QuestionID,OptionID> dataToBeSend);

more information look at this keep coding.

Viral Patel
  • 1,296
  • 1
  • 11
  • 24
AndyShoes
  • 33
  • 2
  • 10
0

Try this code

ArrayList<ArrayList<HashMap<String, String>>> hashMapArrayList1 = new ArrayList<>();
ArrayList<HashMap<String, String>> hashMapArrayList2 = new ArrayList<>();
    for (int i = 0; i < yourlist.size(); i++) {
          try {
                HashMap<String, String> hs = new HashMap<>();
                hs.put("question_id", "" + yourlist.get(i).getQueId().trim());
                hs.put("option_id", "" + yourlist.get(i).getOptionId().trim());                
                hashMapArrayList2.add(hs);
          } catch (Exception e) {
                e.printStackTrace();
          }
        }
      hashMapArrayList1.add(hashMapArrayList2);
      paramas.put("quiz_data", hashMapArrayList1);
gpuser
  • 1,143
  • 1
  • 9
  • 6
  • I tried its making this format, Approx done now just have to replace the hashmap object with array `elearning_id=1&quiz_data=[{option_id=2, question_id=1}, {option_id=6, question_id=2}, {option_id=10, question_id=3}]` – ALI REHMAN Oct 24 '19 at 05:27
  • Just found out that we cannot make associative arrays in java, So this answer is the closest and the correct, Will mark it as the answer. – ALI REHMAN Oct 25 '19 at 05:01