下面的代码:
$url = json_decode($getClient->getBody()->getContents());
dd($url);
显示:
{#302 ▼
+"output": {#304 ▼
+"url": "https://...▶"
}
}
我想将网址存储在变量中,但是使用$urlLink = $url['url'];
时会显示错误:
Cannot use object of type stdClass as array
但是使用$urlLink = $url->url;
也会显示错误:
Undefined property: stdClass::$url
你知道为什么吗?
答案 0 :(得分:0)
这是因为 url 位于output
对象中。
$response = $getClient->getBody()->getContents();
$url = null;
if(!empty($response)) {
$response = json_decode($response);
$url = !empty($response->output->url) ?: $response->output->url : '';
}
// Handle the redirection this way.
// If $url == null then that means no response from API.
// If $url == '' then the file hasn't been completely uploaded.
这就是应该怎么做。