json_encode缺少包含日期的行的一部分


json_encode missing part of row containing a date

代码

$table = array();
$table['cols'] = array(
    array('label' => 'Date', 'type' => 'date'),
    array('label' => 'Orders', 'type' => 'number')
);
    $rows = array();
    while($row = oci_fetch_assoc($stid)) {
        $temp = array();
        $temp[] = array('h' => (int) $row['Date']);
        $temp[] = array('v' => (int) $row['Orders']);
        $rows[] = array('c' => $temp);
    }
    $table['rows'] = $rows;
    $jsonTable = json_encode($table);

更新

感谢WereWolf-The Alpha的答案,它使用了完整的日期,但现在我有一些奇怪的问题,如下所示。

{
   "cols":[
      {
         "label":"Date",
         "type":"date"
      },
      {
         "label":"Orders",
         "type":"number"
      }
   ],
   "rows":[
      {
         "c":[
            {
               "h":"2014'/05'/02 00:00"
            },
            {
               "v":8
            }
         ]
      },
      {
         "c":[
            {
               "h":"2014'/05'/06 00:00"
            },
            {
               "v":10
            }
         ]
      },
      {
         "c":[
            {
               "h":"2014'/05'/07 00:00"
            },
            {
               "v":9
            }
         ]
      },
      {
         "c":[
            {
               "h":"2014'/05'/08 00:00"
            },
            {
               "v":10
            }
         ]
      }
   ]
}

这是因为您使用了以下代码:

$temp[] = array('h' => (int) $row['Date']);

移除(int):

$temp[] = array('h' => $row['Date']);

例如,试试这个:

$d = '2014/05/08 00:00';
echo $d; // 2014/05/08 00:00

现在试试这个:

$d = '2014/05/08 00:00';
$d = (int) $d;
echo $d; // 2014

因为(int)正在解析字符串'2014/05/08 00:00'中的整数,所以它只是排除了/05/08 00:00'中的所有内容,因为/不是int

使用此

json_encode($str, JSON_UNESCAPED_SLASHES);

有关更多信息和其他标志,请参阅文档

同时删除迄今为止的(int)强制转换。