我在这里做错了什么。 我尝试使用MWS Themeforest主题将json_encode发送到dataTables。 这是我的ajax代码:
<?php
include("../inc/connect.inc.php");
error_reporting(E_ALL);
ini_set('display_errors', 1);
$sql = "SELECT vv.id, vv.licenseplate, vv.emergency, vv.alert, vt.name FROM vehicle_vehicle AS vv
INNER JOIN client_user_vehicle_map AS cv ON cv.id_vehicle = vv.id
INNER JOIN vehicle_type AS vt ON vt.id = vv.id_type
WHERE cv.id_user = ".$_GET["idUser"];
$rst = mysql_query($sql);
$val = "";
while($lst = mysql_fetch_array($rst)){
$sql2 = "SELECT id, ignition, date FROM vehicle_tracking WHERE id_vehicle = ".$lst["id"]." ORDER BY date DESC LIMIT 1";
$rst2 = mysql_query($sql2);
while($lst2 = mysql_fetch_assoc($rst2)){
$date = date_create($lst2["date"]);
$comm = date_format($date, 'd-m-Y H:i:s');
if ($lst2["ignition"] == "1"){
$val = "<center><i class='icol32-bullet-green'></i></center>";
}else if ($lst2["ignition"] == "0"){
$val = "<center><i class='icol32-bullet-black'></i></center>";
}
$licenseplate = $lst["licenseplate"];
$data = array($lst["name"], "1", $comm, "1");
$arr[] = array("name" => $licenseplate, "data" => $data);
}
}
$output['aaData'][] = $arr;
echo "<pre>";
print_r($output);
echo "</pre>";
echo json_encode($arr); ?>
我的print_r的结果就是这个数组:
Array(
[aaData] => Array
(
[0] => Array
(
[0] => Array
(
[name] => ITU 2198
[data] => Array
(
[0] => Automóvel
[1] => 1
[2] => 09-05-2014 19:17:55
[3] => 1
)
)
[1] => Array
(
[name] => BANCADA
[data] => Array
(
[0] => Automóvel
[1] => 1
[2] => 09-04-2014 11:10:51
[3] => 1
)
)
[2] => Array
(
[name] => IHC 8764
[data] => Array
(
[0] => Automóvel
[1] => 1
[2] => 09-05-2014 19:22:14
[3] => 1
)
)
[3] => Array
(
[name] => IFT 0003
[data] => Array
(
[0] => ISCA
[1] => 1
[2] => 07-05-2014 15:30:13
[3] => 1
)
)
[4] => Array
(
[name] => IFT 0004
[data] => Array
(
[0] => ISCA
[1] => 1
[2] => 07-05-2014 13:20:37
[3] => 1
)
)
)
))
但我的json_encode是空白的。 你能帮帮我吗? 非常感谢。
答案 0 :(得分:1)
在while(....
之后添加此行$lst2 = array_map('utf8_encode', $lst2);
这会将所有元素转换为utf8。