簡體   English   中英

如何將后端的字段數據附加到 Typo3 中的 JSON 文件中

[英]How append the fields data from backend into JSON file in Typo3

如何將來自 Typo3 中后端公式的數據直接寫入現有的 JSON 文件? 當我從 Typo3 的后端刪除它們時,我以后如何從 JSON 中刪除它們? 所有 JSON 輸入都有時間戳。

先感謝您!

作為 JSON,不是線性文件格式,而是序列化對象。 無法向其附加數據。

你必須做的是:

1) 讀取 json 文件 2) 使用json_decode()獲取 stdObject 或數組 3) 以您想要的方式操作該數據對象/數組。 4) 使用json_encode()將其轉換回字符串.. 5) 將其寫回文件。

// Load The Data
$pathToYourFile = 'paht/somefile.json';
$dataString = file_get_contents($pathToYourFile);
$jsonDataArray = json_decode($dataString, true); // fetch Data as ArrayM
///Maniuplate the data like you want

$jsonDataArray['someValue'] = 'updated Value';

// write it back

$dataString = json_encode($jsonDataArray);
file_put_contents($dataString);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM