Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
421 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 Reply

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;
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...