0

I have to send the following data to a php web service using JSON

The format of data to be send is:

object1{key1:<>,key2:<>Array1({key1<>,key3<>array2 ( {key4:<>,array3({key5:<>}), {}, {},...) }}

My problem is: how can I send the array values to the web service?

manlio
19.1k14 gold badges83 silver badges138 bronze badges
asked Dec 21, 2011 at 8:29

1 Answer 1

1

iam able to add more elemnts to the array. check this

JSONArray datarr = new JSONArray();
 JSONObject obj1;
 JSONObject Array1 = new JSONObject();
 try {
 for(int i=0;i<4;i++){
 obj1 = new JSONObject();
 obj1.put("array1val", 5);
 obj1.put("array2val", 2);
 datarr.put(obj1);
 } 
 Array1.put("Array1", datarr);
 Log.v(null, Array1.toString());
 } catch (JSONException e) {
 // TODO Auto-generated catch block
 e.printStackTrace();
 }

the out put is

{
"Array1":
 [
 {
 "array1val":5,"array2val":2
 },
 {
 "array1val":5,"array2val":2
 },
 {
 "array1val":5,"array2val":2
 },
 {
 "array1val":5,"array2val":2
 }
 ]
}

is this what your looking for?

duggu
38.5k12 gold badges120 silver badges114 bronze badges
answered Dec 21, 2011 at 8:34
1
  • yha did it. but problem is that i am able to send only one value ata time like: Array1[{"array1val":5,"arrayval2":2:}] in one time ths Array1[{"array1val":5,"arrayval2":2:},{"array1val":5,"arrayval2":2:}] Commented Dec 21, 2011 at 10:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.