In a database table there are accented words or with ç. When using json_encode in php to send the result to the view, json breaks due to the parser error. What is the best way to handle these characters before calling json_encode?
Example of how to return from the bank. These objects should be parsed for json.
[0] => Array
(
[usuario_nome] => Oliveira Souza
)
[1] => Array
(
[usuario_nome] => jão çávão
)
[2] => Array
(
[usuario_nome] => joao josjdsojd
)
I was able to pass the data as follows:
$sth = $conn->query("SELECT * FROM v_usuarios where usuario_ativo = 'S' $condicao order by usuario_nome ASC");
$sth->execute();
$datas = array();
while($data = $sth->fetchAll(PDO::FETCH_ASSOC))
array_push($datas,json_encode($data, JSON_UNESCAPED_UNICODE));
$retorno =new Response(($datas[0]));
$retorno->headers->set('Content-Type','application/json; charset=utf-8');
return $retorno;
But would there be any better way?