2012-05-11 31 views
0

我在我的視圖中定義了一個名爲Student的變量。在我看來,如何將Student對象顯示爲JSON?如何在Zend Framework中以JSON格式返回Application_Model 1.11

public function previewAction() 
{ 
    // ... 
    $this->view->student = $student; 
} 

在我preview.phtml觀,我有以下幾點:

<script> 
    // this doesn't return the Application_Model as a JSON object in the html  
    var studentData = <?php echo Zend_Json::encode($this->student); ?>; 
</script> 
+2

請問這個回報把雙引號? – skafandri

回答

1

圍繞PHP標籤

<script> 
    // this doesn't return the Application_Model as a JSON object in the html  
    var studentData = "<?php echo Zend_Json::encode($this->student); ?>"; 
</script> 
+0

這將返回由php生成的json結果作爲JavaScript字符串而不是js對象表示法。 –