gpt4 book ai didi

php - JSONArray 从 android 到 Array php

转载 作者:行者123 更新时间:2023-11-30 03:23:01 25 4
gpt4 key购买 nike

我正在将一些值从 android/java 发送到服务器。

首先我创建一个 JSONArray 对象:

JSONArray JSONsamples = new JSONArray();

然后我按以下方式填充 JSONArray:

 for(.....)
{
if(...)
{
JSONsamples.put(storedArraylist.get(i));
}
}

然后我通过 post 发送值:

userParameters.add(new BasicNameValuePair("samples", JSONsamples.toString()));
.
.
Http_Client.executeHttpPost(getApplicationContext(), POST_url, userParameters);
.

然后在服务器上我尝试将这些值存储到一个 php 数组中,但它不起作用:

 $samplesarray = $_POST["samples"];
$samplesarray = json_decode($samplesarray,true);

在解码之前,如果我回显 $samplesarray ,我只会得到封装在这些\"value\"中的第一个值,在 json_decode 之后,当我回显 $samplesarray 时,我得到一个预期的参数但发现空值错误。

请帮忙。

最佳答案

Magic Quotes 应该关闭,因为它会在您的 " 值之前添加一个 \。这会破坏您案例中的 json 数据。

请在此处详细了解为什么不应使用魔术引号: http://php.net/manual/en/security.magicquotes.whynot.php

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

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