如何在android中的hashmap中发送数组?

时间:2017-08-19 12:44:24

标签: android hashmap retrofit

我想以行格式发送以下数据,如:

  {
  "sender_id":"A1234567",
  "sender_name":"abc",
  "division_name":["test D1","test D2"]
  }

如何在hashmap中发送devision名称?

HashMap<String, String> map = new HashMap<>();
    map.put("sender_id", edSenderId.getText().toString().trim());
    map.put("sender_name", edSenderName.getText().toString().trim());
    map.put("division_name","..." );

1 个答案:

答案 0 :(得分:1)

您可以发送如下代码的数组;

  int childCount = move_st_list.getChildCount();

 ArrayList<String> student_ids = new ArrayList<>();

  // Here I m fetching all students ids from RecyclerView's adapter class....

    for(int i = 0; i < childCount; i++)
    {
        MyAdapter.ViewHolder childHolder = (MyAdapter.ViewHolder) move_st_list.findViewHolderForLayoutPosition(i);

        student_ids.add(studentAttendancePojo.getStudentSerchList().get(i).getiStudentId());
    }

    JSONArray jsArray = new JSONArray(student_ids);

然后在地图中传递;

    map.put("division_name",jsArray);