凌空传递数组作为参数 [英] Volley pass array as parameters

查看:80
本文介绍了凌空传递数组作为参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用截击向我的php后端发送帖子请求,但是我无法将数组作为参数传递...或添加具有相同名称的多个参数,这只会将for循环中的最后一个参数添加到参数

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

我只想将数组,"friendnr"列表传递给我的php后端..

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

thx

推荐答案

您的每个循环都存在错误...

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

这篇关于凌空传递数组作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆