我有一个记录用户视图的网站统计数据库。我想阅读并导出为 JSON。我可以做到,但我想将它们重新写入给定的格式。我该怎么办?
预期的 JSON 代码://源自http://www.highcharts.com/samples/data/jsonp.php?filename=aapl-c.json&callback= ?
callback(/* AAPL historical OHLC data from the Google Finance API */
[
/* Sep 2005 */
[1127088000000,52.64],
[1127174400000,53.19],
[1127260800000,52.11],
[1127347200000,51.90],
[1127433600000,53.20],
[1127692800000,53.84],
[1127779200000,53.44],
[1127865600000,51.08],
[1127952000000,52.34],
[1128038400000,53.61],
...
]);
这是我的代码:
$sql_viewer="select sum(vwr_id) as num,vwr_date from car_viewer where vwr_tid='$_tid' group by year(vwr_date) desc, month(vwr_date) desc";
$result_viewer=mysql_db_query($dbname,$sql_viewer);
while($rec_viewer=mysql_fetch_array($result_viewer)){
$_viewerDate=$rec_viewer['vwr_date'];
$_viewerNum=$rec_viewer['num'];
foreach($rec_viewer as $key=>$val){
$arr[$key]=$val;
}
$main_arr[]=$arr;
}
echo json_encode($main_arr);
结果 JSON:
[{"0":"221944676","num":"221944676","1":"2012-09-01 00:20:08","vwr_date":"2012-09-01 00:20:08"},{"0":"66772926","num":"66772926","1":"2012-08-09 23:35:04","vwr_date":"2012-08-09 23:35:04"},{"0":"609","num":"609","1":"2012-02-20 22:40:29","vwr_date":"2012-02-20 22:40:29"}]
问题是如何将结果 JSON 重写为上述预期格式?问候,