gpt4 book ai didi

php - 将 JSONArray 从 android 发送到 php

转载 作者:行者123 更新时间:2023-11-29 20:35:11 25 4
gpt4 key购买 nike

我将 JSONArray 从我的 android 应用程序传输到我的 php 文件,当我在 php 文件上回显它时,它回显“数组”,但我似乎无法访问数组的内容.

这是我的 php 文件的一部分:

$data = json_decode(file_get_contents('php://input'), true);

$orderJSON = urldecode($_POST['order']);
$orderJSON = json_decode($orderJSON,true);

// Create connection
$conn = mysqli_connect($servername, $username, $password2, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}

echo $orderJSON;

我似乎无法访问内容,它们都返回 null,我使用以下代码在 android 上对 JSONArray 进行编码。

String jsonPost = URLEncoder.encode("order","UTF-8")+"="+URLEncoder.encode(jsonArray.toString(),"UTF-8");

我在发布之前仔细检查了数组是否有数据,它确实显示了加载的内容,即使在 php 文件上,当我注释掉 json_decode() 方法时,它也会回显内容

最佳答案

$orderJSON 是一个数组,您不能使用 echo 在 PHP 中显示数组的内容。请改用 print_r($orderJSON);

关于如何访问数组中的数据请引用:http://php.net/manual/en/language.types.array.php

关于php - 将 JSONArray 从 android 发送到 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31466800/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com