2017-06-22 81 views
0

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

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是我的网址参数,添加在前面的一个。

+0

我迷茫......发生什么事VS你希望发生什么? – MaxPower

+0

对不起,发生什么事是它不能将参数识别为数组,因此它不会添加%5B%5D。我想知道如何放置参数,以便在url中添加%5B%5D。 – jeanf

回答

0

我会做这样的事情与Apache StringUtils的Apache的公地

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()); 
+0

我发送此结构:{“id”:“258”,“fecha2”:“[2017年1月10日]”,“fecha1”:“[2017年1月20日]”,“desde”:“[09:00 AM]“,”hasta“:”[05:00 PM]“,”slot“:”[1 hora]“}但我需要发送:{”id“:”253“,”fecha2“:[ 2017年6月30日“,”fecha1“:[”2017年6月21日“,”desde“:[”01:00 AM“],”hasta“:[”06:00 AM“],”slot“: [“1 hora”]}。如何获得括号内的引号。请 – jeanf

+0

你可以逃脱它并把“[\”21 June,2017 \“]”以获得在 – MaxPower