Reputation: 97
my 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
}
Now my problem is the output , there are \u00d6 in it. the $data is a simple joomla select.
my output is this:
{"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
Upvotes: 1
Views: 436
Reputation: 42582
The issue is basically with JResponseJson
is that it is using json_encode()
. When you don't pass any extra parameters to it, json_encode()
will automatically have this behavior.
To get this to work you need PHP 5.4+ and to pass to json_encode()
the option JSON_UNESCAPED_UNICODE
. See also the page with Predefined JSON Constants
To get back to your issue, replace the line in question with:
echo json_encode($data, JSON_UNESCAPED_UNICODE);
Hope this helps.
Upvotes: 1