JSON-重命名名称/值对

时间:2011-02-21 16:57:36

标签: json kohana-3

干草全部, 我正在使用Kohana 3,我试图整合jquery fullcarlendar插件。用于此插件的命名约定似乎是事件的“标题”,开始日期的“开始”,布尔值的“allday”等等。

查询后我生成了像

这样的json字符串
[{"eventdate":"2011-02-05 06:15:35","name":"EBS, Heriot Watt Graduation Ceremony"},{"eventdate":"2011-02-05 06:16:20","name":"Heriot Watt University Edinburgh Business School Graduation Ceremony 2011"}]

有没有办法做类似

的事情
DB::select('start'=>'simpleevent.eventdate', 'title'=>'simpleevent.name')                     
                    ->from('simpleevent')
                    ->where('YEAR("eventdate")', '=', $todayasarray[0])

基本上在查询之后我在PHP中获得了一个数组数组,然后在

中使用
json_encode($myArray)

那么我可以为每个名称/值对重命名“名称”吗?

`

2 个答案:

答案 0 :(得分:1)

DB::select(array('simpleevent.eventdate', 'start'), array('simpleevent.name', 'title'))                     
                ->from('simpleevent')
                ->where( /*condition*/)

答案 1 :(得分:0)

我试过这个,基本上在我的动作上创建json作为字符串之后我使用了php str_replace()函数,如下所示。

$oldnames = array("name","eventdate");
$newnames = array("title","start");
$v->jsonData = str_replace($oldnames, $newnames, $jsondata); 

仅当您无法按照Dusan

所示更改别名时,此选项才可用
相关问题