1
Hello, my friends.
I am generating a file . json with PHP, but even when it is created it is badly formatted, it is not possible to read its data. See:
{
"0": "6",
"idt1": "6",
"1": "2018-10-19",
"datahora": "2018-10-19",
"2": "1",
"resultado": "1",
"3": "1",
"indicbet": "1",
"4": "Inglaterra - Premier League 2",
"LIGA": "Inglaterra - Premier League 2",
"5": "",
"rh": "",
"6": "",
"ra": "",
"7": " Fulham SubWest Brom Sub",
"TIMEHA": " Fulham SubWest Brom Sub",
"8": "71",
"TARGLG": "71",
"9": "0",
"PLACH": "0",
"10": "2",
"PLACA": "2",
"11": "GREEN",
"RESULT": "GREEN"
}{
"0": "6",
"idt1": "6",
"1": "2018-10-19",
"datahora": "2018-10-19",
"2": "1",
"resultado": "1",
"3": "1",
"indicbet": "1",
"4": "Inglaterra - Premier League 2",
"LIGA": "Inglaterra - Premier League 2",
"5": "",
"rh": "",
"6": "",
"ra": "",
"7": " Fulham SubWest Brom Sub",
"TIMEHA": " Fulham SubWest Brom Sub",
"8": "71",
"TARGLG": "71",
"9": "0",
"PLACH": "0",
"10": "2",
"PLACA": "2",
"11": "GREEN",
"RESULT": "GREEN"
}
As you can see, the brackets are missing at the beginning and end and the commas between the "arrays".
Here the code that generates json:
while($rowJ = mysqli_fetch_array($resultJ)){
if(count($_items) > 1){
//criar JSON/tabela do USUARIO
// Escreve o resultado JSON em arquivo:
$idu = $_SESSION['idu_log_pn'];
$idu = 1;
$pasta = $idu;
$diretorio = "users/".$pasta;
if(!file_exists($diretorio))
{
mkdir("$diretorio", 0777);
}
// Tranforma o array $dados em JSON
$dados_json = json_encode($rowJ, JSON_PRETTY_PRINT);
// Cria o arquivo cadastro.json
// O parâmetro "a" indica que o arquivo será aberto para escrita
$fp = fopen("users/".$idu."/file".$idu.".json", "a");
// Escreve o conteúdo JSON no arquivo
$escreve = fwrite($fp, $dados_json);
// Fecha o arquivo
fclose($fp);
}
}
Anderson, it worked right... Thanks, man!
– Rubens Sgarbi Ayres