Reputation:
My PHP cote return error:
Undefined property: stdClass::$paging in Trying to get property of non-object Use of undefined constant total_items - assumed 'total_items' in
How can I get total_items
value?
This is 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;
} ;
Upvotes: 0
Views: 53
Reputation: 5123
tyr this.
$data ='{"paging":{"total_items":0,"current_page":1,"total_pages":0},"data":[],"facets":null}';
$v = json_decode($data,true);
echo $v['paging']['current_page'];
Upvotes: 1