Ciao ragazzi!
Sto incontrando un problema nella generazione di un file JSON.
Parto da un semplice form PHP:
Premesso che la struttura che voglio ottenere è la seguente:
codice HTML:
{
"records":
[
{"datoX" : "x", "datoY" : "y", "datoZ" : "z"}
{etc etc...}
]
}
Ogni volta che clicco su submit voglio aggiungere un nuovo array (x,y,z)
Codice PHP:
$file = file_get_contents('../json_example.json');
$data = json_decode($file);
unset($file);//prevent memory leaks for large json.
// Inserisco i dati
file_put_contents('../json_example.json',json_encode($data, true));
Mi piacerebbe capire il meccanismo, sulla base di un esempio concreto, così non ve lo chiedo più