为什么MySQL位数据类型php打印unicode?

Joh*_*ker 5 javascript php json extjs

当我的MySQl数据类型为bit(1)时,但是用php打印时json_encode会用unicode写吗?IIS工作正常,
但是在我的专用服务器上,Apache托管将变为unicode。为什么? 在此处输入图片说明

您可以看到LocatingLocating在Mysql数据类型上是位,但打印\ 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);


?>
Run Code Online (Sandbox Code Playgroud)

更新

代表性的数据是正确的,但在使用JavaScript的下面我无法读取定位值IM的问题是,我已经尝试alert了纪录,但blank.i试图定位与type:stringtype:bittype:bytestype: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'}
        ]
    });
Run Code Online (Sandbox Code Playgroud)

Dan*_* W. 1

变量的表示仍然是正确的。

从 PHP 5.4 开始,您可以JSON_UNESCAPED_UNICODE使用json_encode(). 请参阅http://php.net/manual/en/function.json-encode.php

我的猜测是您的 IIS 默认返回未转义的值。

在 Javascript 中你通常会使用parseInt(\u0001)什么。因为它是extjs,所以我不知道。

计划B:

A) 将数据库列从位更改为整数。

B) 在 php 中转换数据库值

while($obj = mysql_fetch_object($rs)) {
  $obj->Locating = (int)$obj-Locating;
  // or try with (string) if (int) fails
  $arr[] = $obj;
}
Run Code Online (Sandbox Code Playgroud)

C) 只需str_replace在 json 输出中:

$json = json_encode($arr);
$json = str_replace('"\u0001"', '"1"', $json);
$json = str_replace('"\u0000"', '"0"', $json);
Run Code Online (Sandbox Code Playgroud)