我得到一個JSON對象腓添加新的JSON對象
{"cms18.test.silverbee.nl":{"domain":"cms18","template":"default"},"dmmd.test.silverbee.nl":{"domain":"dmmd","template":"default"},"opmaat.test.silverbee.nl":{"domain":"opmaat","template":"opmaat"},"opmaatdebiteurenadvies.nl":{"domain":"opmaat","template":"opmaat"},"navbar.test.silverbee.nl":{"domain":"navbar","template":"default"},"test18.test.silverbee.nl":{"domain":"test18testsilverbeenl","template":"test"},"huisartsplus.test.silverbee.nl":{"domain":"huisartsplustestsilverbeenl","template":"huisartsplus"},"robertenrademaker.test.silverbee.nl":{"domain":"robertenrademakertestsilverbeenl","template":"robert-en-rademaker"},"tilburg.test.silverbee.nl":{"domain":"tilburgtestsilverbeenl","template":"default"},"cbk-groningen.test.silverbee.nl":{"domain":"cbk_groningentestsilverbeenl","template":"cbk-groningen"},"getbusyinc.test.silverbee.nl":{"domain":"getbusyinctestsilverbeenl","template":"getbusyinc"}}
,我想添加/推一個新的PHP字符串我給它量身定做的,我有它這樣的我不知道,如果它是正確的。
<?php
$list= file_get_contents('list.json');
$list = json_decode($list, true);
include('veranderen.php');
// Het toevoegen van een nieuwe URL
$url = $_POST['new_url'];
$t_d = $_POST['t_d'];
$t_t = $_POST['t_t'];
$str[$url] = "{domain:".$t_d.","."template:".$t_t."},";
include('delete.php');
include('interface.php');
include('lijst.php');
?>
如果您正在解碼json_object,而不是將已解碼數組中的每個值進行解壓縮,然後再次對其進行編碼並替換文件內容。 – Akshay
你的變量是'$ list',但是你正在改變'$ str'。應該是'$ list [$ url]'。並且不要將新值添加爲JSON字符串。將它作爲數組添加,然後加上'json_encode'。 –