2

I want to send data like packageid[]=1&packageid[]2. The same applies for the amount. The key will be the same, but the value will be different.My Packageid[] would be same and values would be different.and my question is different.

HashMap<String,String> params1 = new HashMap<String,String>();
params1.put("customerId", String.valueOf(helpervalue));
params1.put("vechileId", String.valueOf(vehicalId));
params1.put("timeslotId", String.valueOf(timeSlotId));
params1.put("registrationYear", String.valueOf(registeryear));
params1.put("franchiseId", String.valueOf(helpervalue2));
params1.put("jobDate", String.valueOf(date));
params1.put("vehicleRegistrationNumber", String.valueOf(register));
params1.put("totalAmount", String.valueOf(total)+"&"+getURlFromArray1(strint));`

private String getURlFromArray1(int arr[]) {
    String makeupSTR = "";

    for(int val : arr)
        makeupSTR += arr1Key+"="+val+"&";
    if(makeupSTR.contains("&"))
         makeupSTR = makeupSTR.substring(0, makeupSTR.lastIndexOf("&"));
    return makeupSTR;
}

I am expecting to send the following query string structure:

?access=true&action=place_order&type=Add&franchiseId=1&jobDate=2016-01-30&customerId=1&vehicleRegistrationNumber=1&vehicleMakeId=1&registrationYear=2016&totalAmount=250.36&packageIds[]=1&packageIds[]=2&packageAmounts[]=20&packageAmounts[]=30

which responds with JSON like

{
    status: false,
    displayMessage: "This Slot has just been booked. Please Select a different Time Slot."
}
Manish
  • 35
  • 11
  • this is actual data which i have to send on server .. – Manish Feb 23 '16 at 11:19
  • http://client.zoneonedigital.com/carwash_v2/api/ws/controller/?access=true&action=place_order&type=Add&franchiseId=1&jobDate=2016-01-30&customerId=1&vehicleRegistrationNumber=1&vehicleMakeId=1&registrationYear=2016&totalAmount=250.36&packageIds[]=1&packageIds[]=2&packageAmounts[]=20&packageAmounts[]=30 – Manish Feb 23 '16 at 11:20
  • It's so confusing to read code with for and if statements written that way. Ive added your linked json to the question, I can't see an array there? – Nick Cardoso Feb 23 '16 at 11:38
  • very sorry for rewriting...i have to send exactly this data..&franchiseId=1&jobDate=2016-01-31&customerId=12&vehicleRegistrationNumber=‌​1&vehicleMakeId=1&registrationYear=2016&totalAmount=250.36&packageIds[]=1&package‌​Ids[]=2&packageAmounts[]=20&packageAmounts[]=30 – Manish Feb 23 '16 at 14:05
  • Please don't use the comments for code like text or additional information. If you must clarify something, find the edit link under your question to add anything to your question – OneCricketeer Feb 23 '16 at 14:12
  • Possible duplicate of [How to convert map to url query string?](http://stackoverflow.com/questions/2809877/how-to-convert-map-to-url-query-string) – OneCricketeer Feb 23 '16 at 14:15
  • Another duplicate. http://stackoverflow.com/questions/1861620/is-there-a-java-package-to-handle-building-urls – OneCricketeer Feb 23 '16 at 14:17

1 Answers1

0

You need to decide how to send this "array". You can simply send it as a ;-separated string: key=val1;val2;val3, for example. In server, you split them using ;.

Example:

String values[] = { "1", "2", "3" };
String all = "";
for (String v : values)
   all += v + ";";
all = all.substring(0, all.length() - 1);
String param = "key=" + all;

You can better send json/xml.

  • packageid[]=1&packageid[]=2&packageid[]=3&&packageid[]=4 – Manish Feb 23 '16 at 13:54
  • very sorry for rewriting...i have to send exactly this data..&franchiseId=1&jobDate=2016-01-31&customerId=12&vehicleRegistrationNumber=1&vehicleMakeId=1&registrationYear=2016&totalAmount=250.36&packageIds[]=1&packageIds[]=2&packageAmounts[]=20&packageAmounts[]=30 – Manish Feb 23 '16 at 13:59
  • bro my values are coming ...in a string from previous activity..and now i have convert it into int array...how can i put it as ..key=val1;val2;val3 – Manish Feb 23 '16 at 14:07
  • like this `packageIds=1;2;20;30&registrationYear=2016& ...` –  Feb 24 '16 at 06:09
  • i am not talking about ..how to put static values....i have a String Array which have all packageid...that is strint[i].... – Manish Feb 24 '16 at 06:44
  • Bro see my method private String getURlFromArray1(int arr[]) – Manish Feb 24 '16 at 06:56
  • And exact requirement is...String orderurl="http://client.zoneonedigital.com/carwash_v2/api/ws/controller/?access=true&action=place_order&type=Add&totalAmount=250.36&packageIds[]=1&packageIds[]=2&packageAmounts[]=20&packageAmounts[]=30"....please see my code also... – Manish Feb 24 '16 at 06:58