下面的代码如下:
$url = json_decode($getClient->getBody()->getContents());
dd($url);
显示:
{#302 ▼
+"output": {#304 ▼
+"url": "https://...▶"
}
}
我想将url存储在一个变量中,但使用$urlLink = $url['url'];
时,它显示了错误:
Cannot use object of type stdClass as array
但$urlLink = $url->url;
也显示了一个错误:
Undefined property: stdClass::$url
你知道为什么吗?
发布于 2018-06-23 03:11:28
这是因为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.
这就是应该怎么做的。
https://stackoverflow.com/questions/50994190
复制相似问题