Php json_编码包含日期的行的缺失部分
代码Php json_编码包含日期的行的缺失部分,php,json,Php,Json,代码 $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()
$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);
更新
感谢狼人-阿尔法的回答,它使用的是完整的日期,但现在我有一些奇怪的问题\和/如下所示
{
"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
}
]
}
]
}
用这个
json_encode($str, JSON_UNESCAPED_SLASHES);
有关更多信息和其他标志,请参阅
同时删除迄今为止的
(int)
强制转换。这是因为您使用了以下代码:
$temp[] = array('h' => (int) $row['Date']);
卸下(int)
:
例如,尝试以下方法:
$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
现在试试这个:
$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我试过了,但没什么区别,输出仍然只显示年份,即{“cols”:[{“label”:“Date”,“type”:“日期“},{”标签“{”订单“,”类型“:”数字“}],”行“:[{”c:[{“h”:2014},{“v”:8}},{”c:[{“h”:2014},{“v”:10}]},{”c:[{“h”:2014},{“v”:9},{“c:[{“h”:2014},{“v”:10}]}}}
。谢谢你的回答!我完全错过了,{code>,但现在我有一些奇怪的问题,你看不出这些问题了吗