0
When I want to display the data returned by a JSON, it returns to me NULL. Only when the database information is without accents, it returns me normally:
<?php
include_once 'WSAps_conexao.php';
$cidade =$_POST['cidade'];
$sql = $dbcon->query("SELECT * FROM parques WHERE Cidade = '$cidade'");
if(mysqli_num_rows($sql)>0)
{
while($row = mysqli_fetch_assoc($sql))
{
$res[] = $row;
}
echo json_encode($res);
}
else
{
echo "login_false";
}
?>
Probably your database should not be encoded with UTF8 characters, try so:
json_encode($res, JSON_UNESCAPED_UNICODE)
and tell me if anything comes up when you try to return with the accents.– Fernando VR
Still returning me NULL, my database is configured with utf8_general_ci
– Patrick Camargo
Try to use set_charset('utf8') also as Guilherme’s answer, you need to check if your PHP file is also in UTF8, and if the file that sends the information to your database is also in the same encoding. If you use the Notepad++ software, in the menu
Formatar
, You can check if the document is in the right encoding. It is good to check all the places where the information goes if it is in the same coding.– Fernando VR
http://rmonte.com/acentuacao-no-php-e-mysql-com-utf-8/ This link explains a little about what I’m talking about, the commands are in Mysql, but it’s easy to switch to Mysqli. In the comments you have an example: http://rmonte.com/acentuaca-no-php-e-mysql-com-utf-8/#comment-1895
– Fernando VR
Thank you for the reply, I got by set_charset('utf8'), according to Guilherme’s reply
– Patrick Camargo
@Fernandovr only needs the files to be saved in utf8 and the header/charset if the accents are not escaped in json_encode, but as by default it "escapes", for example "ã" turns " u00e3" so there is no need, and at the time that use on Android (author case) he’ll probably use
JSONobject
(https://developer.android.com/reference/org/json/JSONObject.html), which will recognize the escaped accents and print normally.– Guilherme Nascimento
I understand @Guilhermenascimento, but incredible as it seems I’ve had problems also with accentuation when the file I sent to the database, be in different encoding. It sent to the database in an encoding that the database saved in another one and when displaying the query there was a different result. As I do not know the system of the friend who asked, so sometimes it is good to check all the information path until you find where the error is.
– Fernando VR
Good @Patrickcamargo who turned out all right. Hugs ^^
– Fernando VR