使用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
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