JSON Restful API Accents

Asked

Viewed 1,127 times

3

Good morning, everyone,

I am creating an API for study, but I have some problems with accents.

When I do a search, I have an answer of not found.

Goes down a test.

Esse primeiro teste ele funciona corretamente, mas a consulta não chega até os acentos

Esse segundo teste ele não funciona, faço a pesquisa com os acentos

Esse terceiro teste ele também não funciona, faço a pesquisa com a url codificada

There would be some solution for me to resolve this situation?

P.S.: Slim Framework Usage

1 answer

0

When receiving the data in PHP use an Encode to transfer the data to the variable:

header("Content-Type: text/html; charset=UTF-8",true);
$json = json_decode(file_get_contents('php://input',true));
$texto= utf8_encode($json->{"texto"});

and to return the data:

echo json_encode($response,JSON_UNESCAPED_UNICODE);

Make sure the JSON sent is in UTF-8

Browser other questions tagged

You are not signed in. Login or sign up in order to post.