如何获得“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 中获取“404”文本(“status”: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
关于Php Json 获取多个对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31833122/