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?

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?

Sign up to request clarification or add additional context in comments.

1 Comment

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:}]

Your Answer

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.