gpt4 book ai didi

php - 如何在 json 中输出 javascript 日期

转载 作者:可可西里 更新时间:2023-10-31 22:59:44 25 4
gpt4 key购买 nike

我正在尝试时间线图表: http://code.google.com/apis/visualization/documentation/gallery/annotatedtimeline.html#Data_Format数据以 JSON 提要的形式出现。

Google 想要这样的数据:

    {
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()' 这样的字符串定界符包裹它。

最佳答案

我只是将函数包装在 %% 个字符中,如下所示:

$something = array('%%new Date(...) %%','somevalue');
$json = json_encode($something);

并删除了这些 %% 字符和它们旁边的字符串分隔符。

$json = preg_replace("/(('|\")%%|%%(\"|'))/",'', $json);

关于php - 如何在 json 中输出 javascript 日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3146075/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com