0
i have a php file that generates a json in array for another application to read, however everything is working but the json is coming with the [] of the list, and my application can only read from {}, have to remove before generating the json as [] ?
Code that generates json
<?php
$result = $con->query($Sql_Query);
$rows = [];
while ($row = mysqli_fetch_assoc($result)) {
array_push($rows, $row);
}
<br>
$json = json_encode($rows);
<br>
$file = 'file.json';
<br>
file_put_contents($file, $json);
<br>
mysqli_close($con);
<br>
?>
Result of json
[{"ID":"10","name":"name","email":"[email protected]","id_user":"12345"}]
if it is an array will always come with
[]
, with{}
only if it is a single object, I think you need to change your application that reads, because it is expecting a single object– Ricardo Pontual