我想将mysql查询的结果转换为json格式
查询返回很多fo记录,但是json的print_r不返回任何内容
$sql="select concat(sig,doc)as Order,date,age from ordertable";
$res = $conn->query($sql);
while($row = $res->fetch_assoc())
{
$rows[] = $row;
}
$json = json_decode($rows, true);
fwrite($handle, "json: ".print_r($json,true)." \n\n");
答案 0 :(得分:0)
您需要按以下两行更改此内容,
$json = json_encode($rows); // to convert it into json internal array
//$json = json_encode($rows,JSON_FORCE_OBJECT); // to convert it json object
fwrite($handle, "json: $json \n\n");
这应该可以解决问题。