我需要发送以下的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();
}
}
正如我所做的那样,在我的网址的参数中添加%5B%5D,就像在上一个网址中一样。
答案 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());