将PHP结果数组转换为JSON

我想将结果数组转换为PHP中的JSON格式。这是我的代码:


$row = mysql_fetch_array($result)

我想转换$row为JSON格式并将JSON数据传递给jQuery插件。


犯罪嫌疑人X
浏览 338回答 2
2回答

湖上湖

json_encode 在php> 5.2.0中可用:echojson_encode($row);

UYOU

$result = mysql_query($query) or die("Data not found."); $rows=array(); while($r=mysql_fetch_assoc($result)){ $rows[]=$r;}header("Content-type:application/json"); echo json_encode($rows);
打开App,查看更多内容
随时随地看视频慕课网APP