Php 如何解析json中的对象

Php 如何解析json中的对象,php,json,Php,Json,我想将json对象显示为var,我正在尝试使用api在Anonfile上上载文件,但在上载文件后,它会以json格式显示结果。所以我想在json中获取特定的对象,这是我的代码 if (isset($_POST['submit'])) { $url = sprintf('https://api.anonfiles.com/upload', $token); $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt

我想将json对象显示为var,我正在尝试使用api在Anonfile上上载文件,但在上载文件后,它会以json格式显示结果。所以我想在json中获取特定的对象,这是我的代码

if (isset($_POST['submit'])) {

$url = sprintf('https://api.anonfiles.com/upload', $token);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'file' => curl_file_create(
$_FILES['file']['tmp_name'],
$_FILES['file']['type'],
$_FILES['file']['name']
),
]);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$json = curl_exec($ch);

curl_close($ch);

$result = json_decode($json);

if (is_object($result) && $result->status) {
echo $json;

如果您想访问JSON中的特定对象,您已经在使用
$result->status
进行访问了。
json\u解码
您的json数据后,只需使用
$result->[json节点]
即可获取所需的数据。

当我以您为例时,上载文件时出现错误。以下是节点````````````````````状态:true,“数据”:{“文件”:{“url”:{“完整”:“}”,元数据:{“id”:“v5W9Y6v3o6”,“名称”:“advent.jpg”,“大小”:{“字节”:15934,“可读”:“15.93 KB”}你到底想要什么?我只想在Object中获取文件url如果是这样,你也必须从根遍历所有相关节点。就像这样,
$result->data->file->url->full
可恢复致命错误:stdClass类的对象无法转换为字符串