我需要制作一个PHP JSON像这样从MySQL数据库使用PHP:PHP:生成没有{}的json?
[['Staff Welfare', 'london', 'map-marker-icon.png'] , ['perfect', 'London', 'map-marker-icon.png'] , ['Fare Trade', 'essex', 'map-marker-icon.png'] , ['Fare Trade', 'london', 'map-marker-icon.png'] ,]
这是我已经试过:
$return_arr = array();
$sql = "SELECT * FROM restaurants";
if ($result = mysqli_query($db_conx, $sql)){
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$row_array['id'] = $row['id'];
$row_array['location'] = $row['location'];
$row_array['name'] = $row['name'];
$row_array['type'] = $row['type'];
array_push($return_arr,array($row_array));
}
}
mysqli_close($db_conx);
echo json_encode($return_arr);
但上面的代码回声的是这样的:
[[{"id":"1","location":"london","name":"Staff","type":"indian"}], [{"id":"2","location":"London","name":"perfect","type":"chinese"}],[{"id":"3","location":"essex","name":"Trade","type":"kebab"}],[{"id":"5","location":"london","name":"Fare Trade","type":"kebab"}]]
有人可以请让我知道我可以如何删除{}
并删除column names
以及我的j儿子回声就像我在找什么?
那需要的格式是无效的JSON它甚至不接近JSON –
它有效的JSON,你必须1)更改'''''''2)在结尾']'之前删除'''。 –