这是我的代码,用于显示数据库中的JSON输出。
while ($row = mysql_fetch_array($result)) {
$row_array['option_id'] = $row['option_id'] . "<br>";
$row_array['option_name'] = $row['option_name'] . "<br>";
$row_array['option_value'] = $row['option_value']. "<br>";
$row_array['autoload'] = $row['autoload']. "<br><br>";
//push the values in the array
array_push($json_response, $row_array);
}
echo json_encode($json_response);
输出如下:
[{"option_id":"262
","option_name":"carl
","option_value":"manere
","autoload":"
"},{"option_id":"263
","option_name":"John
","option_value":"John Smith
","autoload":"
"},{"option_id":"265
","option_name":"James
","option_value":"James Doe
","autoload":"
"},{"option_id":"266
","option_name":"Dwight
","option_value":"Dwight Howard
","autoload":"
"}]
我想要输出就像这样。
[
{
"option_id": 262,
"option_name": "carl",
"option_value": "carl manere",
"autoload": " "
}, . . .etc
我该如何格式化呢?
答案 0 :(得分:1)
<?php
echo json_encode($json_response);