I want to add Data before the array and it is written into the converted json. I have checked that there are no errors when converting, but why isn't there?
This the code
$response = array();
while($row =mysqli_fetch_assoc($result))
{
$response[] = $row;
}
echo json_encode($response);
//write to json file
$fp = fopen('op.json', 'w');
fwrite($fp, json_encode('{"Data":', $response), '}');// JSON_PRETTY_PRINT
fclose($fp);
Previous results like this
[
{
"id": "6",
"name": "kiko",
"score": "999"
},
{
"id": "9",
"name": "johyn",
"score": "88"
},
{
"id": "12",
"name": "aaaani",
"score": "99"
}
]
I want the results like this
{
"Data": [
{
"id": "6",
"name": "kiko",
"score": "999"
},
{
"id": "9",
"name": "johyn",
"score": "88"
},
{
"id": "12",
"name": "aaaani",
"score": "99"
}
]
}