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.

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Directly Map wont work as we have array of array of map. Not directly map
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);

2 Comments

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}]
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.