【发布时间】:2013-08-01 20:24:37
【问题描述】:
当我的 MySQl 数据类型是 bit(1) ,但是当用 php 打印时 json_encode 会用 unicode 写吗? IIS 工作正常,
但在我的专用服务器中,Apache 托管将变为 unicode。为什么?
可以看到Locating,Locating上Mysql的数据类型是bit,但是打印的是\u0001?为什么?
这是我的编码GET方法get-googlemarker.php得到这个结果
<?php
mysql_connect("localhost", "root", "123456") or die("Could not connect");
mysql_select_db("db_gps") or die("Could not select database");
$parent_id = $_GET['mainid'];
$query = "SELECT *
FROM tbl_locate AS a
INNER JOIN
(
SELECT MainID, Max(DateTime) AS DateTime
FROM tbl_locate
GROUP BY MainID
) AS b
ON a.MainID = b.MainID
AND a.DateTime = b.DateTime
LEFT JOIN
(
SELECT b.PicData
, b.PicUploadedDateTime
, b.MainID
FROM (SELECT MainID,Max(PicUploadedDateTime) as PicUploadedDateTime
FROM tbl_picture
group by MainID
) l
JOIN tbl_picture b
ON b.MainID = l.MainID AND b.PicUploadedDateTime = l.PicUploadedDateTime
) AS c
ON a.MainID = c.MainID";
$rs = mysql_query($query);
$arr = array();
while($obj = mysql_fetch_object($rs)) {
$arr[] = $obj;
}
echo json_encode($arr);
?>
更新
表示数据是正确的,但问题是当我使用下面的 javascript 时,我无法读取定位值,
我试过 alert 记录,但是是空白的。我试过用 type:string , type:bit , type:bytes , type:int 定位,
但不起作用。无法在alert 中显示任何内容
Ext.define('GoogleMarkerModel', {
extend: 'Ext.data.Model',
fields: [
{name: 'ID', type: 'int'},
{name: 'Locating', type: 'int'},
{name: 'MainPower', type: 'int'},
{name: 'Acc', type: 'int'},
{name: 'PowerOff', type: 'int'},
{name: 'Alarm', type: 'int'},
{name: 'Speed', type: 'int'},
{name: 'Direction', type: 'int'},
{name: 'Latitude', type: 'float'},
{name: 'Longitude', type: 'float'},
{name: 'DateTime', type: 'datetime'},
{name: 'MainID', type: 'int'},
{name: 'IOState', type: 'int'},
{name: 'OilState', type: 'int'},
{name: 'PicUploadedDateTime', type: 'datetime'},
{name: 'PicData', type: 'str'}
]
});
【问题讨论】:
-
您将图像存储在数据库中?
-
@Dagon 是的,我是,但我不认为这与问题有关?
-
这是二进制值 0001 的有效 JSON 编码。我在这里看不到错误。我想知道“IIS 运行良好”是什么意思。
-
我只是认为
u代表unsigned。当您想将变量与 javascript 一起使用时,它应该可以正常工作。它仍然是相同的数据类型,只是呈现方式不同。 -
IIS 将只返回 0 或 1,但在 Apache 中将返回
\u0000或\u0001
标签: php javascript json extjs