Php 如何从SPLObjectStorage中的响应访问“计数”?
我明白了: 我怎样才能收到计数。我尝试了两种方法,比如$r->count和$r->count 这是一个要点Php 如何从SPLObjectStorage中的响应访问“计数”?,php,guzzle,Php,Guzzle,我明白了: 我怎样才能收到计数。我尝试了两种方法,比如$r->count和$r->count 这是一个要点 // Results is an SplObjectStorage object where each request is a key foreach ($results as $request) { // Get the result (either a ResponseInterface or RequestException) $result
// Results is an SplObjectStorage object where each request is a key
foreach ($results as $request) {
// Get the result (either a ResponseInterface or RequestException)
$result = $results[$request];
if ($result instanceof ResponseInterface) {
// Interact with the response directly
$r = $result->getBody();
echo $r;
} else {
// Get the exception message
echo $result->getMessage();
}
}
因为这是一个JSON字符串,所以可以使用
我自己找到了答案。我必须使用get_object_vars。将对象转换为数组
$r = $result->getBody();
$response=json_decode($r);
$s = get_object_vars($response);
dd($s->count);
不,获取此错误:未定义属性:stdClass::$count那么您拥有的字符串可能不完全是该字符串。在更新的回答中看到小提琴奇怪,我得到的是完全相同的身体,但错误就在那里;精确打印文本?var_dump$r;也有助于识别任何额外的角色为什么会有反对票?我不明白。
$r = $result->getBody();
$response=json_decode($r);
$s = get_object_vars($response);
dd($s->count);