[英]How can i send array of array with key value pairs with retrofit
Here is what i want to send in a post request with retrofit any idea?这是我想通过 retrofit 发送的帖子请求中的任何想法?
"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.它必须是动态的,因为我不知道管理员会添加多少测验问题。
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.