Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
411 views
in Technique[技术] by (71.8m points)

android - Volley pass array as parameters

i'm ussing volley to send post requests to my php backend but i'm unable to pass an array as parameters... or add multiple parameters with the same name which only add the last param in the for loop to the params

this code works but only return the last number as parameter and not both numbers:

  protected Map<String, String> getParams() {
            ArrayList<String> numbers = new ArrayList<String>();
            numbers.add("+431111111111");
            numbers.add("+432222222222");

            Map<String, String> params = new HashMap<String, String>();

            for(String object: numbers){
                params.put("friendnr[]", object);
            }
            return params;
        }

i just want to pass an array, list of "friendnr" to my php backend..

thx

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

your for each loop is buggy...

protected Map<String, String> getParams() {
        ArrayList<String> numbers = new ArrayList<String>();
        numbers.add("+431111111111");
        numbers.add("+432222222222");

        Map<String, String> params = new HashMap<String, String>();

        int i=0;
        for(String object: numbers){
            params.put("friendnr["+(i++)+"]", object);
            // you first send both data with same param name as friendnr[] ....  now send with params friendnr[0],friendnr[1] ..and so on 
        }
        return params;
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...