duanqun9740 2014-09-04 09:47
浏览 36
已采纳

使用JSON将数组发布到php

I want to send an Array to a php file. I can do it with a single string, so the connection etc. works. But i dont know how to do it with an array and how to get the array at the php file.

So this is my class:

String[] nonUserArray = new String[ohne.size()];
        for (int i = 0; i < ohne.size(); i++) {

            nonUserArray[i] = ohne.get(i).getnummer();
            System.out.println("Array "+nonUserArray[i]);
        }


            List<Name ValuePair> params = new ArrayList<NameValuePair>();
             // This is still wrong...
            params.add(new BasicNameValuePair("nummer[]", nonUserArray[]));

My php file still is:

<?php 
$response = array();
if (isset($_POST['nummer'])) {
    $nummer = $_POST['nummer'];    
    require_once __DIR__ . '/db_connect.php';

    $db = new DB_CONNECT();

    //Hier wird die ID ausgelesen
    $getIdAusMySQL = 0;
    $getIdAusMySQL = mysql_query("SELECT id FROM User WHERE nummer = '$nummer'"); 

   ...

I dont know how to receive the array and put it in a loop inside the php file.

´ By the way, can someone tell me a good oppertunity to find errors inside a php file. something like system.out.println() in java/android. Thanks

  • 写回答

1条回答 默认 最新

  • dongzhina7098 2014-09-04 09:58
    关注

    Instead of posting the data as an array, you can JSON ENCODE the array into a json string and post it.

    Later on form post you can JSON DECODE your string back to an array.

    For error debugging you can use

    echo "your message"

    to add debug points.

    For better error tracking you can set error reporting on.

    Refer: error reporting in php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog