如何发送java字符串数组到PHP?使用凌空(Android) [英] How to send java string array to php? using volley (Android)

查看:76
本文介绍了如何发送java字符串数组到PHP?使用凌空(Android)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将以下数据发送到我的php,但是如果我放置多个s1变量,程序就会崩溃。

I am trying to send following data to my php but program crashes if I put more than one s1 variable.

Java代码:

    //my java code goes here
        @Override
    protected Map<String, String> getParams() throws AuthFailureError {
        Map<String, String> params = new HashMap<>();
            params.put("s1",max[0]);
            params.put("s1",max[1]);
            params.put("s1",max[3]);
        return params;
    }

PHP代码:

    //my php code goes here
        <?php
     $con = mysqli_connect('localhost','myuser','mypass');
     mysqli_select_db($con,'mydb');

     $checked = $_POST["s1"];

     $SQL = "INSERT INTO TABLE VALUES ('$checked[0]','$checked[1]','$checked[2]')";
     mysqli_query($con,$SQL);
    ?>


推荐答案

地图只能存储一个键和一个值,重复不允许使用键,因此简而言之,您只是发送一个值,并尝试使用索引(不存在)来获取多个值,因此例外。

Map can only store one key and one value, duplicate keys are not allowed so in short you are just sending a single value and trying to fetch multiple values using index (which does not exists) hence the exception

解决方案:可以使用不同的键并使用服务器上的键获取值或发送整个数组

Solution : Either use different keys and fetch values using those keys on server or send the whole array

要发送整个数组,只需创建 JSONObject JSONArray 请求而不是String

To send whole array , simply Create JSONObject or JSONArray request instead of String

这篇关于如何发送java字符串数组到PHP?使用凌空(Android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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