我正在通过 JSON 和 PHP 从 URL 检索数据。我很难将对象分开并显示数据。PHP 代码似乎一直在工作,直到我进入 for 循环。
$jsonurl = 'http://myweb/api.php';
$json = file_get_contents($jsonurl);
$json_output = json_decode($json);
foreach ($json_output->Monitoring AS $monitoring) {
foreach ($monitoring->Status AS $Status){
echo $Status->Emailed;
echo $Status->Status;
}
这是我的数据结构:
object(stdClass)#12 (1)
{ ["Monitoring"]=> array(10) { [0]=> object(stdClass)#13 (14)
{
["Status"]=> string(30) "HTTP/1.1 302 Moved Temporarily"
["Emailed"]=> string(1) "0" }
[1]=> object(stdClass)#14 (14) {
["Status"]=> string(30) "HTTP/1.1 302 Moved Temporarily"
["Emailed"]=> string(1) "0" }
[2]=> object(stdClass)#15 (14) {
["Status"]=> string(30) "HTTP/1.1 302 Moved Temporarily"
["Emailed"]=> string(1) "0" }
[3]=> object(stdClass)#16 (14) {
["Status"]=> string(30) "HTTP/1.1 302 Moved Temporarily"
["Emailed"]=> string(1) "0" }
} }