2
Attached the photo of my return JSON
<?php
header("Content-Type: text/html; charset=UTF-8",true);
$array1 = array();
$contador = 0;
$estado="online";
if (!$enlace = mysql_connect('meuHost', 'meuUser', 'Minhasenha')) {
echo '{}';
exit;
}
if (!mysql_select_db('MinhaBaseDados', $enlace)) {
echo '{}';
exit;
}
mysql_set_charset("uft-8");
$sql = 'select distinct(param_curso.curso_designacao) as Universidade, count(candidato_curso.id) as Quantidade from param_curso
inner join ciclocurso on param_curso.id=ciclocurso.curso_id
inner join candidato_curso on ciclocurso.id=candidato_curso.ciclo_curso_id
group by param_curso.curso_designacao;';
$resultado = mysql_query($sql, $enlace);
if (!$resultado) {
echo "{}";
}
while ($fila = mysql_fetch_assoc($resultado)) {
$validacoes =new Cursos_validacoes;
$validacoes->universidade = $fila["Universidade"];
$validacoes->quantidade = $fila["Quantidade"];
if($validacoes->universidade==null){
$validacoes->universidade="vazio";
}
$array1[$contador] = $validacoes;
$contador = $contador + 1;
}
echo json_encode($array1);
mysql_close($enlace);
class Cursos_validacoes{
public $universidade;
public $quantidade;
}
?>
What is your problem? I didn’t quite understand what you meant by JSON accentuation return, the data is not coming in UTF8 database format ?
– Gabriel Rodrigues
This is the problem the data does not come in UTF8 format, and I do not know why.
– Gabriel Manuel
I advise you to use PDO, this mysql class is already deprecated, but if you use it you will need to set the charset utf, you can do something like $link = mysql_connect('localhost', 'user', 'password'); mysql_set_charset('utf8',$link);
– Gabriel Rodrigues
Adding mysqli_query($myconnection, 'SET CHARACTER SET utf8'); before query select if I am wrong solve your problem.
– haykou
It does not! Allow the return to be in the format encoded by the function and ready. JSON was created to facilitate the exchange of data between several languages through Javascript. The returned format has the encoding of.
– StillBuggin