【发布时间】:2019-03-02 04:38:21
【问题描述】:
我计算的行数是我的 JSON 结果 但是我也在尝试计算结果中的项目数。
行计数有效,但项目计数无效。 出现错误:试图在 $FLCount 行上获取非对象的属性
代码如下
// Counts The Rows - WORKS
$row = $obj->response->result->Accounts->row;
$countRows = count($row);
// Counts The FL Items ( Doesn't Work )
$FLCount= $obj->response->result->Accounts->row->FL;
$countItems = count($FLCount);
JSON 结果片段
{
"response": {
"result": {
"Accounts": {
"row": [
{
"no": "1",
"FL": [
{
"val": "ITEM 1",
"content": "XX"
},
{
"val": "ITEM 2",
"content": "XX"
},
{
"val": "ITEM 3",
"content": "XX"
}
]
}
]
}
}
}
}
【问题讨论】:
-
FL不是row的直接子代,因此您需要通过循环row和访问FL或硬编码行位置$obj->response->result->Accounts->row[0]->FL;来访问它