我正在使用jQuery日历,它需要这种格式的JSON:
string(138) "[{"title":"Event1","start":"2012-06-10"},{"id":222,"title":"Event2","start":"2012-06-20","end":"2012-06-22","url":"http:\/\/yahoo.com\/"}]"
但是,我得到的是:
[{"title":"Event1","start":"2012-06-10"},{"id":222,"title":"Event2","start":"2012-06-20","end":"2012-06-22","url":"http:\/\/yahoo.com\/"}]array(2) { [0]=> array(2) { ["title"]=> string(6) "Event1" ["start"]=> string(10) "2012-06-10" } [1]=> array(5) { ["id"]=> int(222) ["title"]=> string(6) "Event2" ["start"]=> string(10) "2012-06-20" ["end"]=> string(10) "2012-06-22" ["url"]=> string(17) "http://yahoo.com/" } }
问题是有人说string(138)
,而另一个是array
。
这是我的代码:
$myHolder = array();
$myHolder[] = array(
'title' => "Event1",
'start' => "$year-$month-10",
);
$myHolder[] = array(
'id' => 222,
'title' => "Event2",
'start' => "$year-$month-20",
'end' => "$year-$month-22",
'url' => "http://yahoo.com/"
);
echo json_encode(($myHolder));
答案 0 :(得分:0)
这会产生您正在寻找的确切字符串:
ob_start();
var_dump( json_encode( $myHolder));
$output = trim( ob_get_clean());
但是,我怀疑将var_dump
生成的字符串长度/格式作为JS日历的输入会有所帮助。然而,如果这是你需要的,那就是你如何得到它。