您好我在PHP中使用json_encode函数遇到了一些困难。 我有一个带有哈希(uniq ID)的对象,但它可以使用这种格式5808e70581507,因为" e"用数字包围我认为json_encode试图将这个伙伴设置为整数。
我的对象如下:
stdClass Object
(
[id] => 16
[title] => userinf2
[desc] => Travail →
[startoff] => 2016-10-20 05:00:00
[stop] => 2016-10-20 13:00:00
[status] => 1
[allDay] => 0
[code_mode] => M
[uid] => 31250
[gid] => 502935
[recurrence_id] =>
[recurrence_mode] =>
[recurrence_repeat_every] =>
[recurrence_repeat_day] =>
[recurrence_end_mode] =>
[recurrence_end_date] =>
[recurrence_end_number] =>
[multiple_timeschedule_id] => 5808e70581507
[start] => 2016-10-20 05:00:00
[end] => 2016-10-20 13:00:00
[color] => #7AE7BF
[className] => working uid_31250 code_mode_M gid_502935
)
有没有办法让它按原样运行?
代码:
echo json_encode($events[6], JSON_NUMERIC_CHECK);
var_dump($events[6]->multiple_timeschedule_id); // string(13)
作业代码:
function _oms_planning_planning_get()
{
try {
global $user;
$intervenants = _oms_planning_get_cab_intervenants();
$sql = 'SELECT * FROM planning_event WHERE 1=1 AND (';
$params_sql = array();
foreach ($intervenants as $key => $a_user) {
$sql .= ' uid =:uid' . $key . ' OR ';
$params_sql[':uid' . $key] = $a_user->uid;
}
$sql = substr($sql, 0, -3);
$sql .= ')';
$result = db_query($sql, $params_sql);
$db_events = $result->fetchAll();
$events = array_map(function ($db_event) use ($intervenants) {
$db_event->start = $db_event->startoff;
$db_event->end = $db_event->stop;
$db_event->color = (isset($db_event->gid) && intval($db_event->gid) > 0) ?
_oms_planning_planning_get_color_from_gid($db_event->gid) :
_oms_planning_planning_get_color_from_uid($intervenants, $db_event->uid);
$db_event->className = ($db_event->status == 1) ? 'working ' : 'idleness ';
$db_event->className .= 'uid_' . $db_event->uid . ' ';
$db_event->className .= 'code_mode_' . $db_event->code_mode . ' ';
$db_event->className .= 'gid_' . $db_event->gid;
return $db_event;
}, $db_events);
return $events;
} catch (Exception $e) {
print_r($e);
}
}
Mysql列类型:multiple_timeschedule_id varchar(200)utf8_general_ci