Php Json 进入多个对象

Php Json Get inside Multiple Object

如何获得“404”文本输出

 {
"status": 200,
"msg": "OK",
"result": {
    "jnQARJd2Xi8": {
        "id": "jnQARJd2Xi8",
        "status": 404,
        "name": false,
        "size": false,
        "sha1": false,
        "content_type": false
    }
}

}

我的代码是:

$id = "jnQARJd2Xi8";
$url = "https://api.openload.io/1/file/info?file=".$id;

$response = file_get_contents($url);
$obj = json_decode($response);
$openload = $obj->{'status'};

echo $openload."<br>";

我需要从这个 json ("status": 404)

中获取“404”文本

你可以这样做:

<?php
$json = '
 {
"status": 200,
"msg": "OK",
"result": {
        "jnQARJd2Xi8": {
            "id": "jnQARJd2Xi8",
            "status": 404,
            "name": false,
            "size": false,
            "sha1": false,
            "content_type": false
        }
    }
}
';

$obj = json_decode($json);
echo $obj->result->jnQARJd2Xi8->status; //Returns 404

变化自

$openload = $obj->{'status'};

$openload = $obj->result->$id->{'status'};

完整代码

$id = "jnQARJd2Xi8";
$url = "https://api.openload.io/1/file/info?file=".$id;

$response = file_get_contents($url);
$obj = json_decode($response);
$openload = $obj->result->$id->{'status'};

echo $openload."<br>";