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 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程