我找不到解决方案,所以我使用 XML-RPC 协议(protocol)从服务器获取数据,我需要请求一个命令,该命令的服务器需要空字典(“像这样 {} ”,在 python 中我可以做到这一点)但是在 PHP 中如何使用 PHP 中的空字典发出请求?
server.list("Example", {}, user_id) //PYTHON
上面的代码在 Python 中有效,我从服务器得到了成功的响应
但是
$client->query("list", "Example", {}, $user_id); // PHP
上面的行不起作用并给我错误。我尝试了空数组,但服务器的响应是我必须提供字典而不是数组。
我尝试过
$empty = array(""=>"");
$client->query("list", "Example", $empty, $user_id);
在这一行中,结果是空数组,没有任何错误。 我也尝试了“NULL”和“”(空字符串),但没有任何结果和错误!
如何在 PHP 中像在 Python 中一样执行此命令?非常感谢。
最佳答案
尝试 (object) null
获取“空”对象。 See here :
If an object is converted to an object, it is not modified. If a value of any other type is converted to an object, a new instance of the stdClass built-in class is created. If the value was NULL, the new instance will be empty.
关于php - Python空字典和PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25352456/