1

Call from android is as follows

CallWebServiceTask task = new CallWebServiceTask(6, this,
                "Fetching Data From Server");
        int key = 0;
        for(int i = 0; i < localIds.size(); i++) {
           key = localIds.keyAt(i);
           // get the object by the key.
           task.addNameValuePair("ids", ""+key);
        }

        task.execute(url);

This one will add a list of ids to the key ids.

On my php when I do, print_r($_POST); it returns just Array() as a string.

How, do I extract the array values in php in an array. Thanks.

2 Answers 2

1

Just encode your array as a JSONArray and post it to your PHP server, much easier to work with this way.

CallWebServiceTask task = new CallWebServiceTask(6, this,
                "Fetching Data From Server");
task.addNameValuePair("ids", new JSONArray(localIds));
task.execute(url);
Sign up to request clarification or add additional context in comments.

7 Comments

How exactly? Shall I not use name value pair?
Yes use it , get rid of the loop because you are overwriting the post keys
So you want me to send {id1 : 1, id2 : 2, id3 : 3} instead of {ids : 1,2,3}?
depends or like this { "ids" : [ 1, 2, 3] } , but most importantly send it as JSON
But the way, I've done it, it should go as a json right? And the json should look exactly like ^the one mentioned in your comment. Or am I getting something wrong here.
|
0
CallWebServiceTask task = new CallWebServiceTask(6, this,
                "Fetching Data From Server");
        int key = 0;
        for(int i = 0; i < localIds.size(); i++) {
           key = localIds.keyAt(i);
           // get the object by the key.
           task.addNameValuePair("ids"+i, ""+key);
        }

        task.execute(url);

Comments

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.