JSON 提要:
{
"Group": [
{
"name": "HolderOne",
"operators": [
{
"username": "ken",
"status": 3
},
.....etc.....
代码:
<?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
?>
我想说如果用户名是 Ken(或者我在编写更多代码时指定的任何内容)显示相应的状态。
所以...
echo $data->Group[0]->operators[0]->username; //WORKS!
但...
foreach($data->Group->operators as $operator) {if($operator->username == "ken") {echo $operator->status;}}
...不 - 可能很明显,但任何人都可以看到我的问题吗?
干杯安迪