<?php require'mysql_connect.php'; $result = mysqli_query($con,"SELECT * FROM news");
$n=0;
while ($row = mysqli_fetch_array($result)) {
$arr[$n++]= array(
"title" => $row['title'],
"describe" => $row['describe'],
"content_url" => $row['content_url'],
"picture_url" => $row['picture_url'],
"time" => $row['time']
);
}
echo json_decode($arr);
?>
运行结果: Warning: json_decode() expects parameter 1 to be string, array given in C:\wamp64\www\news\News.php on line 19请问如何修改?
json_decode 是解码,json_encode 才是编码解码后不是对象就是数组,用 echo 也是打印不出来的