我已经编写了一个 php 代码来从 mysql 数据库制作 JSON 文件。当我检查 JSON 文件时,它显示一些数据 NULL,尽管我的数据库没有 NULL 数据。这是我的 PHP 代码:
$selectQuery = "SELECT tour_code, day, schedule_title, details FROM tbl_tour_details WHERE status=0";
$response = array();
$posts = array();
$result = mysql_query($selectQuery) or die ("Errored Query: ".$selectQuery);
if(mysql_num_rows($result))
{
while($row = mysql_fetch_assoc($result))
{
$tour_code = $row['tour_code'];
$day = $row['day'];
$schedule_title = $row['schedule_title'];
$details = $row['details'];
$posts[] = array('tour_code'=>$tour_code, 'day'=>$day, 'schedule_title'=>$schedule_title, 'details'=>$details);
}
}
$response['posts'] = $posts;
$fp = fopen('..//webservices//json//tour_details.json','w');
fwrite($fp, json_encode($response));
fclose($fp);
在这里,DATATYPE 和 Size 是:
tour_code = int
day = int
schedule_title = varchar(150)
details = text
我的数据是这样的:
tour_code =1
day = 3
schedule_title = "Singapore – Genting Highland By Coach (350 KM 5 HRS)"
details = "This Morning Is The Day Of FUN And Adventure For The Family. Enjoy Spectular Rides And Shows At The Ever-Popular Genting Outdoor Theme Park With Its Myriad Attractions For The Young And Old Alike. Take An Exciting Drive In The Antique Car Or Daring Spins On The Roller Coaster, It’s A Magical Adventure Of Fun And Excitement For The Whole Family!
Over Night At Hotel First World Deluxe Or Theme Park Or Awana Resort Or Similar.
(Breakfast, Lunch & Dinner)"
这是我的 json 文件(如果为 null、/r、/n 则包含): json 文件
这是我的 var_dump 文件(将一些数据截断为“...”) var_dump 文件
这是我的print_r($posts)
文件(完全正确)
print_r($posts file
:)