0
JSON提要:JSON PHP的ForEach
{
"Group": [
{
"name": "HolderOne",
"operators": [
{
"username": "ken",
"status": 3
},
.....etc.....
CODE:
<?php
$json = file_get_content('path to feed');
$data=json_decode($json);
echo $data->cGroup[0]->operators[0]->username; //WORKS!
if (is_array($data->Group->operators))
{ foreach($data->Group->operators as $operator)
{if($operator->username == "ken") {echo $operator->status;}}
} else { echo 'NOT AN ARRAY'; } //DOESNT WORK - DISPLAYS NOT AN ARRAY
?>
我想說的用戶名是否肯(或者我指定我的代碼更)顯示把對應的狀態。
所以......
echo $data->Group[0]->operators[0]->username; //WORKS!
但是......
foreach($data->Group->operators as $operator) {if($operator->username == "ken") {echo $operator->status;}}
......不 - 可能是一些顯而易見的,但任何人都可以看到我的問題嗎?
乾杯 安迪
Bazinga !謝謝比利,工作過。 – webservicesco