我正在嘗試解析來(lái)自 Firebase 實(shí)時(shí)數(shù)據(jù)庫(kù)實(shí)例的 JSON,并將其顯示在表格中。我可以從 URL 返回 JSON 并將其存儲(chǔ)在 PHP 中,但我似乎無(wú)法顯示它。JSON 輸出如下所示:{"\"1\"":{"itemDescription":"This is a description of the item.","itemName":"Item Name","itemValue":{"costAmount":200,"costType":"dol"}},"\"2\"":{"itemDescription":"This is an item description.","itemName":"Item Name 2","itemValue":{"costAmount":500,"costType":"dol"}}}在 PHP 中,我正在執(zhí)行以下操作來(lái)獲取數(shù)據(jù):<?php$json_string_itemData = file_get_contents("ENDPOINT/items.json");$itemData = json_decode($json_string_itemData);?>在表中,我正在執(zhí)行以下操作:<?phpforeach ($itemData as $item){ echo '<td>' . $item->itemName . '</td>';}?>我在 test.php 中收到錯(cuò)誤警告:為 foreach() 提供的參數(shù)無(wú)效。線(xiàn)路錯(cuò)誤就是上面提到的那個(gè)。知道如何解析數(shù)據(jù)嗎?
在 PHP 中攝取 Firebase 實(shí)時(shí)數(shù)據(jù)庫(kù) JSON
函數(shù)式編程
2021-11-05 10:42:07