在URL中发送ArrayList值

时间:2017-06-22 15:42:16

标签: java android json httprequest

我需要发送以下的arraylist值:starDateS,endDateS,starHourS,endHourS和intervalS。在参数中:fecha1,fecha2,desde,hasta,slotH。一个网址

   private String intervalS [] = new String[30];

    private String starHourS [] = new String[30];

    private String endHourS [] = new String[30];

    private String starDateS [] = new String[30];

    private String endDateS [] = new String[30];

IdProf="258";


intervalSelected = (String) adapSpinnerIntervalT.getItem(position);

intervalS [0] = intervalSelected;

starHourSelected = (String) adapSpinnerStarH.getItem(position);

starHourS[0] = starHourSelected;

endHourSelected = (String) adapSpinnerEndH.getItem(position);

endHourS[0] = endHourSelected;

mStarDate = mDpDay + " " + mMonth + "," + mDpYear;

starDateS[0] = mStarDate;

mEndDate = mDpDay + " " + mMonth2 + "," + mDpYear;

endDateS [0] = mEndDate;

ServerConnection.setDataAvailab =" http://www.saludvitale.com/app/disponibilidad?idUser=";

private void setDataAvaliability (String IdProf, String[] endDateS, String[] starDateS, String[] intervalS, String[] starHourS, String[] endHourS) {

UrlDataAva=ServerConnection.setDataAvaliab+IdProf+"&fecha2="+endDateS[0]+"&fecha1="+starDateS[0]+"&slotH="+intervalS[0]+"&desde="+starHourS[0]+"&hasta="+endHourS[0];

   try {

            JsonObject objPayload = new JsonObject();
            ServerConnection.SendHTTPRequet(getActivity(), UrlDataAva, objPayload, new OnComplete() {
                @Override
                public void onRequestComplete(Exception e, String result) {
                    handleDataAva(result);
                }
            });
        }catch (Exception e) {
            e.printStackTrace();
        }
}

网址发送应如下:http://www.saludvitale.com/app/disponibilidad?idUser=253&fecha2%5B%5D=30+June%2C+2017&fecha1%5B%5D=21+June%2C+2017&slotH%5B%5D=1+hora&desde%5B%5D=01%3A00+AM&hasta%5B%5D=06%3A00+AM

正如我所做的那样,在我的网址的参数中添加%5B%5D,就像在上一个网址中一样。

1 个答案:

答案 0 :(得分:0)

我会使用Apache commons的Apache StringUtils

做类似的事情
StringBuilder builder = new StringBuilder(setDataAvaliab+IdProf);
builder.append("&fecha=[").append(StringUtils.join(endDateS, ",")).append("]"); //append until each parameter is covered
String url = URLEncoder.encode(builder.toString());