PHP格式的POST数据问题 [英] POST data in PHP formatting issue

查看:76
本文介绍了PHP格式的POST数据问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法通过POST将一些参数发送到.php文件.当我调用var_dump($_POST);时,得到以下输出:

I've managed to send some parameters via POST to a .php file. When I invoke var_dump($_POST);, I get the following output:

["{"abc":"1","def":"2"}"]=>
string(0) ""

我已经尝试处理了很多很多次,但是我似乎无法访问String中的变量. json_decode甚至不起作用.这是怎么回事?

I've tried to process this many, many times but I can't seem to access the variables inside the String. json_decode doesn't even work on it. What's going on here?

推荐答案

通过某种方式,您已经成功地传输了以其值作为键且没有附加值的数据,因此您需要用访问服务器的任何代码来解决该问题(也许您在对象上使用了JSON.Stringify而不是仅仅传递了该对象?).在解决此问题之前,您可以像这样访问数据:

Somehow you have managed to transmit your data with its value as the key and no attached value, so you need to address that in whatever code is accessing the server (Perhaps you used JSON.Stringify on the object instead of just passing the object?). Until you have fixed that, you can access your data like this:

$json = json_decode(array_keys($_POST)[0]);
print_r($json);

输出:

stdClass Object (
    [abc] => 1
    [def] => 2 
)

这篇关于PHP格式的POST数据问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆