我的PHP cote返回错误:
未定义属性:stdClass :: $ paging in试图获取非对象的属性 使用未定义的常量total_items - 假设' total_items'在
如何获得total_items
值?
这是JSON:
{
"paging": {
"total_items": 0,
"current_page": 1,
"total_pages": 0
},
"data": [],
"facets": null
}
$content = file_get_contents($urll);
$clean_content = removeBomUtf8($content);
$decoded = json_decode($clean_content);
foreach ($decoded->data as $data)
{
$total_items = (string)$data->paging[0]->total_items;
echo total_items;
} ;
答案 0 :(得分:1)
$data ='{"paging":{"total_items":0,"current_page":1,"total_pages":0},"data":[],"facets":null}';
$v = json_decode($data,true);
echo $v['paging']['current_page'];