搜索了很多小時後,我發佈了這個問題。我有一個名爲$responses
的變量,它輸出編碼的JSON對象,如下所示。計算JSON對象的數量
[
{
"notification_id": 4936,
"notification_title": "Bridge construction",
"notification_category": "Activities of extraterritorial organizations",
"notification_posted_date": "19/09/16",
"notification_time_left": "2016/10/11 12:45:00",
"notification_by_company": "The Media Company"
}
]
有一個以上的對象,我想用下面的代碼來計算數字。
echo json_encode($responses);
echo count($responses);
但是由於某種原因它不起作用。我也試過這個:
$JsonDecode = json_decode($responses, true);
echo $JsonDecode;
主要問題是打印JSON和獲取對象的數量。任何幫助都感激不盡。
在第二個代碼,你忘了'計數' – nospor
你可以提供整個JSON? – Archish
這是完整的JSON響應至今不過關當然,對象可以被降低,並在同一時間的增加,由於字數限制我不能發佈完整的JSON響應 [ { 「notification_id」:4936, 「notification_title 「:」橋樑建設「, 」notification_category「:」域外組織和機構的活動「, 」notification_posted_date「:」19/09/16「, 」notification_time_left「:」2016/10/11 12:45:00 「, 」notification_by_company「:」The Media Company「 } ] –