Joomla Json UTF8

时间:2014-02-01 14:54:15

标签: php joomla

我的view.html.php

class LigaportalViewJsonarticles extends JViewLegacy
{
    /**
     * Display the view
     */
     public function display($tpl = null)
    {
    // Get the document object.
    $document = JFactory::getDocument(); 
    $document->setMimeEncoding('application/json');
    JRequest::setVar('tmpl', 'component');   
    $ligaId = JRequest::getVar("competitionID",null,"get","String");
    $limit = JRequest::getVar("limit",null,"get","String");
    $model = $this->getModel();
    $data = $model->getContent($ligaId, $limit*5);
   //  parent::display($tpl);  
    //Deaktivierung der gesamten Layout-Komponente, 
    //die für html, head, meta und body-Tags zuständig ist
 //echo  utf8_encode($data);
    parent::display($tpl);


    echo new JResponseJson( $data);
    jexit();;
}//function 
}

现在我的问题是输出,其中有\ u00d6。 $ data是一个简单的joomla选择。

我的输出是:

{"success":true,"message":null,"messages":null,"data":    [{"ligaid":"33","title":"Transfernews in der O\u00d6-Liga - nun auch Champions League-Glanz in Bad Ischl","publish_up":"2014-01-30 18:50:20"},{"ligaid":"33","title":"SV Gmundner Milch holt 4 Talente","publish_up":"2014-01-30 12:56:02"},{"ligaid":"33","title":"SC Marchtrenk zieht zweite Verst\u00e4rkung an Land","publish_up":"2014-01-28 09:53:51"},{"ligaid":"33","title":"O\u00d6-Ligisten im Testspieleinsatz","publish_up":"2014-01-26 18:21:38"},{"ligaid":"33","title":"UFC Eferding: Keine Transfers, aber intensive Vorbereitung","publish_up":"2014-01-26 09:01:27"}]}

THX

1 个答案:

答案 0 :(得分:1)

问题基本上是JResponseJson,因为它正在使用json_encode()。如果您未向其传递任何额外参数,json_encode()将自动出现此行为。

要使其工作,您需要PHP 5.4 + 并将选项json_encode()传递给JSON_UNESCAPED_UNICODE。另请参阅包含Predefined JSON Constants

的页面

要回到您的问题,请将相关行替换为:

 echo json_encode($data, JSON_UNESCAPED_UNICODE);

希望这有帮助。