jQuery没有识别Symfony JSON?

我正在尝试从Symfony获取我的JSON数据,但它似乎没有正常工作。 以下是symfony代码的片段:

$this->getResponse()->setHttpHeader('Content-Type', 'application/json; charset=utf-8'); return $this->renderPartial('listJsonResponse', array('jsonSlots' => json_encode($this->jsonQuery))); 

以上工作正常并击中局部。 我所偏爱的一切都是这样的:

  

现在根据Firebug的说法,它可以正常填充。 以下是回复的副本

[{ “ID”: “1”, “schedule_day”: “星期一”, “START_TIME”: “9点00分00秒”, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “2”},{“编码“:” 2″ , “schedule_day”: “星期一”, “START_TIME”: “9点15分零零秒”, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”:“3 “ ”schedule_day“: ”星期一“, ”START_TIME“: ”9时30分00秒“, ”concurrent_appointments“: ”2“, ”CURRENTCOUNT“: ”0“},{ ”ID“: ”4“,” schedule_day “:” 星期一 “ ”START_TIME“: ”9时45分00秒“, ”concurrent_appointments“: ”2“, ”CURRENTCOUNT“: ”0“},{ ”ID“: ”5“, ”schedule_day“:” 周一“ ”START_TIME“: ”10:00:00“, ”concurrent_appointments“: ”2“, ”CURRENTCOUNT“: ”0“},{ ”ID“: ”6“, ”schedule_day“: ”星期一“,” START_TIME “:” 10″ 时15分00秒, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”: “7”, “schedule_day”: “星期一”, “START_TIME”:“10 :30:00″ , “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”: “8”, “schedule_day”: “星期一”, “START_TIME”:“十点45分00秒“ ”concurrent_appointments“: ”2“, ”CURRENTCOUNT“: ”0“},{ ”ID“: ”9“, ”schedule_day“: ”星期一“, ”START_TIME“: ”11:00:00“,” concurrent_appointments “:” 2″ , “CURRENTCOUNT”: “0”},{ “ID”: “10”, “schedule_day”: “星期一”, “START_TIME”:“11点十五分00秒 “ ”concurrent_appointments“: ”2“, ”CURRENTCOUNT“: ”0“},{ ”ID“: ”11“, ”schedule_day“: ”星期一“, ”START_TIME“: ”11点30分00秒“,” concurrent_appointments “:” 2″ , “CURRENTCOUNT”: “0”},{ “ID”: “12”, “schedule_day”: “星期一”, “START_TIME”: “11点45分○○秒”, “concurrent_appointments”:“2 “ ”CURRENTCOUNT“: ”0“},{ ”ID“: ”13“, ”schedule_day“: ”星期一“, ”START_TIME“: ”12:00:00“, ”concurrent_appointments“: ”2“,” CURRENTCOUNT “:” 0 “},{” ID “:” 14″ , “schedule_day”: “星期一”, “START_TIME”: “12时15分○○秒”, “concurrent_appointments”: “2”, “CURRENTCOUNT”:“0 “},{” ID “:” 15″ , “schedule_day”: “星期一”, “START_TIME”: “12:30:00”, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”: “16”, “schedule_day”: “星期一”, “START_TIME”: “12时45分零零秒”, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”: “17”, “schedule_day”: “星期一”, “START_TIME”: “13:00:00”, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”: “18”, “schedule_day”: “星期一”, “START_TIME”: “十三时15分00秒”, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”: “19”, “schedule_day”: “星期一”, “START_TIME”: “13时30分00秒”, “concurrent_appointments”: “2”, “CURRENTCOUNT” : “0”},{ “ID”: “20”, “schedule_day”: “星期一”, “START_TIME”: “十三点45分00秒”, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0” },{ “ID”: “21”, “schedule_day”: “星期一”, “START_TIME”: “14:00:00”, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{” ID “:” 22″ , “schedule_day”: “星期一”, “START_TIME”: “14点15分00秒”, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”:” 23″ , “schedule_day”: “星期一”, “START_TIME”: “14时30分00秒”, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”: “24”,” schedule_day “:” 星期一 “ ”START_TIME“: ”14点45分00秒“, ”concurrent_appointments“: ”2“, ”CURRENTCOUNT“: ”0“},{ ”ID“: ”25“, ”schedule_day“:”星期一 “ ”START_TIME“: ”15:00:00“, ”concurrent_appointments“: ”2“, ”CURRENTCOUNT“: ”0“},{ ”ID“: ”26“, ”schedule_day“: ”星期一“,” START_TIME “:” 15点15分00″ 秒, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”: “27”, “schedule_day”: “星期一”, “START_TIME”:” 15时30″ 分00秒, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”: “28”, “schedule_day”: “星期一”, “START_TIME”:“15:45: 00″ , “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”: “29”, “schedule_day”: “星期一”,“start_t IME “:” 16点○○分00″ 秒, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”: “30”, “schedule_day”: “星期一”, “START_TIME”:”十六时15分00″ 秒, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”: “31”, “schedule_day”: “星期一”, “START_TIME”:“16:30: 00″ , “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”: “32”, “schedule_day”: “星期一”, “START_TIME”: “16时45分00秒”,” concurrent_appointments “:” 2″ , “CURRENTCOUNT”: “0”},{ “ID”: “33”, “schedule_day”: “星期一”, “START_TIME”: “十七点○○分00秒”, “concurrent_appointments”:” 2″ , “CURRENTCOUNT”: “0”},{ “ID”: “34”, “schedule_day”: “星期一”, “START_TIME”: “17时15分○○秒”, “concurrent_appointments”: “2”,” CURRENTCOUNT “:” 0 “},{” ID “:” 35″ , “schedule_day”: “星期一”, “START_TIME”: “17时30分○○秒”, “concurrent_appointments”: “2”, “CURRENTCOUNT”:” 0 “},{” ID “:” 36″ , “schedule_day”: “星期一”, “START_TIME”: “17点45分00秒”, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”}]

请注意,如果我取出Content / Type标题,它会略有变化。 我得到与上面相同的响应选项卡,但也有一个html选项卡,上面解析为html。 其中显示如下:

[{ “ID”: “1”, “schedule_day”: “星期一”, “START_TIME”: “9点00分00秒”, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “2”},{“编码“:” 2″ , “schedule_day”: “星期一”, “START_TIME”: “9点15分零零秒”, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”:“3 “ ”schedule_day“: ”星期一“, ”START_TIME“: ”9时30分00秒“, ”concurrent_appointments“: ”2“, ”CURRENTCOUNT“: ”0“},{ ”ID“: ”4“,” schedule_day “:” 星期一 “ ”START_TIME“: ”9时45分00秒“, ”concurrent_appointments“: ”2“, ”CURRENTCOUNT“: ”0“},{ ”ID“: ”5“, ”schedule_day“:” 周一“ ”START_TIME“: ”10:00:00“, ”concurrent_appointments“: ”2“, ”CURRENTCOUNT“: ”0“},{ ”ID“: ”6“, ”schedule_day“: ”星期一“,” START_TIME “:” 10″ 时15分00秒, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”: “7”, “schedule_day”: “星期一”, “START_TIME”:“10 :30:00″ , “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”: “8”, “schedule_day”: “星期一”, “START_TIME”:“十点45分00秒“ ”concurrent_appointments“: ”2“, ”CURRENTCOUNT“: ”0“},{ ”ID“: ”9“, ”schedule_day“: ”星期一“, ”START_TIME“: ”11:00:00“,” concurrent_appointments “:” 2″ , “CURRENTCOUNT”: “0”},{ “ID”: “10”, “schedule_day”: “星期一”, “START_TIME”:“11点十五分00秒 “ ”concurrent_appointments“: ”2“, ”CURRENTCOUNT“: ”0“},{ ”ID“: ”11“, ”schedule_day“: ”星期一“, ”START_TIME“: ”11点30分00秒“,” concurrent_appointments “:” 2″ , “CURRENTCOUNT”: “0”},{ “ID”: “12”, “schedule_day”: “星期一”, “START_TIME”: “11点45分○○秒”, “concurrent_appointments”:“2 “ ”CURRENTCOUNT“: ”0“},{ ”ID“: ”13“, ”schedule_day“: ”星期一“, ”START_TIME“: ”12:00:00“, ”concurrent_appointments“: ”2“,” CURRENTCOUNT “:” 0 “},{” ID “:” 14″ , “schedule_day”: “星期一”, “START_TIME”: “12时15分○○秒”, “concurrent_appointments”: “2”, “CURRENTCOUNT”:“0 “},{” ID “:” 15″ , “schedule_day”: “星期一”, “START_TIME”: “12:30:00”, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”: “16”, “schedule_day”: “星期一”, “START_TIME”: “12时45分零零秒”, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”: “17”, “schedule_day”: “星期一”, “START_TIME”: “13:00:00”, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”: “18”, “schedule_day”: “星期一”, “START_TIME”: “十三时15分00秒”, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”: “19”, “schedule_day”: “星期一”, “START_TIME”: “13时30分00秒”, “concurrent_appointments”: “2”, “CURRENTCOUNT” : “0”},{ “ID”: “20”, “schedule_day”: “星期一”, “START_TIME”: “十三点45分00秒”, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0” },{ “ID”: “21”, “schedule_day”: “星期一”, “START_TIME”: “14:00:00”, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{” ID “:” 22″ , “schedule_day”: “星期一”, “START_TIME”: “14点15分00秒”, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”:” 23″ , “schedule_day”: “星期一”, “START_TIME”: “14时30分00秒”, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”: “24”,” schedule_day “:” 星期一 “ ”START_TIME“: ”14点45分00秒“, ”concurrent_appointments“: ”2“, ”CURRENTCOUNT“: ”0“},{ ”ID“: ”25“, ”schedule_day“:”星期一 “ ”START_TIME“: ”15:00:00“, ”concurrent_appointments“: ”2“, ”CURRENTCOUNT“: ”0“},{ ”ID“: ”26“, ”schedule_day“: ”星期一“,” START_TIME “:” 15点15分00″ 秒, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”: “27”, “schedule_day”: “星期一”, “START_TIME”:” 15时30″ 分00秒, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”: “28”, “schedule_day”: “星期一”, “START_TIME”:“15:45: 00″ , “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”: “29”, “schedule_day”: “星期一”,“start_t IME “:” 16点○○分00″ 秒, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”: “30”, “schedule_day”: “星期一”, “START_TIME”:”十六时15分00″ 秒, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”: “31”, “schedule_day”: “星期一”, “START_TIME”:“16:30: 00″ , “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”},{ “ID”: “32”, “schedule_day”: “星期一”, “START_TIME”: “16时45分00秒”,” concurrent_appointments “:” 2″ , “CURRENTCOUNT”: “0”},{ “ID”: “33”, “schedule_day”: “星期一”, “START_TIME”: “十七点○○分00秒”, “concurrent_appointments”:” 2″ , “CURRENTCOUNT”: “0”},{ “ID”: “34”, “schedule_day”: “星期一”, “START_TIME”: “17时15分○○秒”, “concurrent_appointments”: “2”,” CURRENTCOUNT “:” 0 “},{” ID “:” 35″ , “schedule_day”: “星期一”, “START_TIME”: “17时30分○○秒”, “concurrent_appointments”: “2”, “CURRENTCOUNT”:” 0 “},{” ID “:” 36″ , “schedule_day”: “星期一”, “START_TIME”: “17点45分00秒”, “concurrent_appointments”: “2”, “CURRENTCOUNT”: “0”}]

我知道JSON函数正在命中,但它没有解析成功函数并提醒我任何类型的数据。 JavasScript如下所示,并包含在jquery ready标记中

 $.getJSON('/frontend_dev.php/module/listJSONSlots', function(data) { alert(data); }); 

任何想法为什么我无法得到警报?

您无需渲染模板,可以跳过该模板并直接从操作中返回一些内容。 试试这个:

 return $this->renderText(json_encode($this->jsonQuery)); 

你需要的是修改你的偏见

 getRaw('jsonSlots'); ?> 

或者从动作中使用更简单的方法

 $this->getResponse()->setHttpHeader('Content-Type', 'application/json; charset=utf-8'); $this->renderText(json_encode($this->jsonQuery)); 

尝试使用json_encode($input, true)强制它作为对象进行编码。

从技术上讲,JSON的顶级容器必须是一个对象(用{}括起来),而不是一个数组(用[]括起来)。

JSON对象上的属性值可以是数组,但数组不是JSON对象。

我不知道Synfony及其renderPartial方法。 但显然它取代了他们的&...;特殊人物&...; 当量。 您应该寻找一种方法来禁用它