我正在尝试使用 php 将 json 字符串转换为数组。
我的php版本是7.0
我收到此错误:
PHP Fatal error: Uncaught Error: Call to undefined function GuzzleHttp\json_decode()
这是存在问题的代码:
$adjunto1 = $value['archivo'];
$adjunto2 = json_decode($adjunto1, TRUE); //this is teh line with the error
$value['archivo'] 来自数据库,如果我看到里面我得到:
string(155) "{"nombre":["ejemploxls"],"archivoContenido":["id.--ejemploxls--fecha-26-04-2020-10-08.xls"],"fecha":["26-04-2020-10-08"],"size":[5632],"extension":["xls"]}"
当我使用 json_encode() 将数组转换为 json 字符串时,数组如下所示:
array(5) {
["name"]=>
string(11) "ejemplo.xls"
["type"]=>
string(24) "application/vnd.ms-excel"
["tmp_name"]=>
string(14) "/tmp/php7M0gVS"
["error"]=>
int(0)
["size"]=>
int(5632)
}
这个错误是什么?什么是GuzzleHttp?
最佳答案
似乎您从 GuzzleHttp 进行了某种隐式导入。
Guzzle是一个可扩展的 PHP HTTP 客户端。
Here is来自 GuzzleHttp 命名空间的 json_decode
php-function 的包装器,这可能会导致您的问题。
作为一个快速解决方案,只需在函数调用之前添加斜杠:
$adjunto2 = \json_decode($adjunto1, TRUE);
如果您想从我这里获得更详细的答案,请添加您的名单use-statements从你的 php 文件的开头开始。另外,includes
列表(如果有的话)也会有所帮助。我需要更多背景信息才能更准确。
关于php - GuzzleHttp 尝试在 php 7 安装中将 JSON 字符串解码为数组时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61442104/