问题描述
我正在尝试访问徽标和图标的 JSON 数组的图像字符串。
这是我所拥有的,但它不起作用。
Iterator
我试过了
$FinalResponseImages = $responseImages->getBody();
$thingImages = json_decode($FinalResponseImages,true);
$logo = $thingImages["logo"]['image'];
$icon = $thingImages['icon']['image'];
但还是什么都没有。
json_decode() 的关联数组如下
$logo = $thingImages{'logo'}->image;
$icon = $thingImages{'icon'}->image;
任何帮助将不胜感激。
解决方法
您错过了“响应”数组位。例如。 $thingImages['response']['logo']['image']
。
<?php
$thingImages = [
'statusCode' => 200,'response' => [
'logo' => [
'safe' => true,'image' => 'https://assets.brandfetch.io/7fb7161ad320475.png','svg' => null,],'icon' => [
'image' => 'https://assets.brandfetch.io/a407773817604b9.png',];
$logo = $thingImages['response']['logo']['image'];
$icon = $thingImages['response']['icon']['image'];
var_dump($logo); // https://assets.brandfetch.io/7fb7161ad320475.png
var_dump($icon); // https://assets.brandfetch.io/a407773817604b9.png