Php Joomla Json UTF8
my view.html.phpPhp Joomla Json UTF8,php,joomla,Php,Joomla,my view.html.php class LigaportalViewJsonarticles extends JViewLegacy { /** * Display the view */ public function display($tpl = null) { // Get the document object. $document = JFactory::getDocument(); $document-&g
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 select
我的输出是:
{"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问题主要在于
JResponseJson
使用的是json\u encode()
。当您不向其传递任何额外参数时,json\u encode()
将自动具有此行为
要使其正常工作,您需要PHP5.4+,并将选项json\u UNESCAPED\u UNICODE
传递到json\u encode()。另请参见带有
要回到您的问题,请将有问题的行替换为:
echo json_encode($data, JSON_UNESCAPED_UNICODE);
希望这有帮助。为什么会有问题?