如何在json中输出javascript日期 [英] How to output javascript Date in json
本文介绍了如何在json中输出javascript日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试时间轴图表:
http://code.google.com/apis/visualization/documentation/gallery/annotatedtimeline.html#Data_Format
数据即将以JSON订阅源的形式发布。
I am trying to the timeline chart: http://code.google.com/apis/visualization/documentation/gallery/annotatedtimeline.html#Data_Format Data is coming in the form of a JSON feed.
Google希望数据如下所示:
Google wants the data as something like this:
{
version:'0.6',
reqId:'0',
status:'ok',
sig:'4641982796834063168',
table:{
cols:[
{
id:'A',
label:'NEW A',
type:'string'
},
{
id:'B',
label:'B-label',
type:'number'
},
{
id:'C',
label:'C-label',
type:'datetime'
}
],
rows:[
{
c:[
{
v:'c'
},
{
v:3.0,
f:'3'
},
{
v:new Date(2008,
3,
30,
0,
31,
26 ),
f:'4/30/08 12:31 AM'
}
]
}
]
}
}
如何输出Date函数而不将其包装在字符串分隔符中,如'Date()' 。
How can I output the Date function without it being wrapped in string delimiters like 'Date()'.
推荐答案
我简单地将函数包装在%%字符中,如下所示:
I simply wrapped the functions in %% characters like so:
$something = array('%%new Date(...) %%','somevalue');
$json = json_encode($something);
删除这些%%字符及其旁边的字符串分隔符。
And removed these %% characters and the string delimiters next to them.
$json = preg_replace("/(('|\")%%|%%(\"|'))/",'', $json);
这篇关于如何在json中输出javascript日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文