php - Python空字典和PHP

标签 php dictionary

我找不到解决方案,所以我使用 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/

相关文章:

c++ - 如何获取字典键?

php - INSERT ... ON DUPLICATE KEY UPDATE - 不更新特定字段?

php - 在涉及 PDO 事务的嵌套原子操作方面需要帮助

php - 将关联数组与 preg_replace 结合使用

javascript - 获取多行中选择选项的值

image - 图片字段不包含字典

c# - 直接从 Dictionary<> 获取 KeyValuePair<>

php - Codeigniter 电子邮件发送问题

python - 将 XML 解析为列表字典 Python/Django

python - 将 dict 的 pandas dataframe 列扩展为 dataframe 列