我正在尝试从 PHP 中的 JSON 文件中解析一些数据。现在,我让它在本地工作,但是当我把它放到网站上时,我收到了警告错误( Warning: Invalid argument supplied for foreach() )
请帮忙,我对此很陌生,并且绕着圈子阅读并试图弄清楚。
基本上,我想列出所有“艺术家”并包括他们的姓名、UUID 和图像。
JSON
{
"items": [
{
"title": null,
"itemType": "artist",
"moreTrackingTitle": "All Artists",
"items": [
{
"Artist": "Artist One",
"UUID": "364226",
"Image": "http://theurl.com",
},
{
"Artist": "Artist Two",
"UUID": "1513513",
"Image": "http://theurl.com",
},
{
"Artist": "Artist Three",
"UUID": "214141",
"Image": "http://theurl.com",
}
]
},
],
"nextPageToken": null
}
PHP
$request = wp_remote_get( 'http://EXTERNAL-JSON-FILE' );
$body = wp_remote_retrieve_body( $request );
$data =json_decode($body, true);
foreach($data as $k1 => $v1) {
foreach($v1 as $k2 => $v2) {
foreach($v2 as $k3 => $v3) {
foreach($v3 as $artist) {
echo $artist['Artist'];
echo $artist['UUID'];
echo $artist['Image'];
}
}
}
}
BIG阳