Home Accents are not shown using volley
Reply: 1

Accents are not shown using volley

Manuel Morales
1#
Manuel Morales Published in 2018-01-12 22:34:02Z

Download the information without problem, but the accents appear in strange letters.

 StringRequest request = new StringRequest(Request.Method.POST, getString(R.string.municipio_noticias), new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    if (!response.equals("null")){
                        try {
                            basededatos.EliminarNoticias();
                            JSONArray jsonArray = new JSONArray(response);
                            for (int i = 0; i < jsonArray.length(); i++) {
                                basededatos.RegistrarNoticias(
                                        jsonArray.getJSONObject(i).getInt("folio"),
                                        jsonArray.getJSONObject(i).getString("encabezado"),
                                        jsonArray.getJSONObject(i).getString("fecha"),
                                        jsonArray.getJSONObject(i).getString("texto"),
                                        jsonArray.getJSONObject(i).getString("autor"));

                                Log.d("ENCABEZADO",jsonArray.getJSONObject(i).getString("encabezado"));
                               //D/ENCABEZADO: Entrega de un apoyo económi... <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                            }
                            ConsultarNoticias();
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {

                }
            }) {
                @Override
                protected Map<String, String> getParams() throws AuthFailureError {
                    Map<String, String> parameters = new HashMap<String, String>();
                    return parameters;
                }
            };
            requestQueue.add(request);
            return null;
        }
    }

how download the accents information?

My Php File

      <?php
if($_SERVER["REQUEST_METHOD"]=="POST"){
    include('conexion.php');
    $result  = mysqli_query($con,"SELECT * FROM noticias") or mysqli_error($con);
    while ($row = $result->fetch_assoc()) {
         $arr[] = $row;
    }
    $json = json_encode($arr,JSON_UNESCAPED_UNICODE);
    echo $json;
}
?>

with POSTMAN result:

the information is correctly show. the problem is android json download :/

Amine Choukri
2#
Amine Choukri Reply to 2018-01-12 22:37:00Z

please try to use this code for sending and receiving JSON with utf-8 encoding:

try {
    URL url = new URL("your url");
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();

    conn.setDoOutput(true);

    OutputStreamWriter writer = new OutputStreamWriter(
            conn.getOutputStream(), "UTF-8");
    String request = "your json";
    writer.write(request);
    writer.flush();
    System.out.println("Code:" + conn.getResponseCode());
    System.out.println("mess:" + conn.getResponseMessage());

    String response = "";
    BufferedReader reader = new BufferedReader(new InputStreamReader(
            conn.getInputStream(), "UTF-8"));
    String line;
    while ((line = reader.readLine()) != null) {
        response += line;
    }

    System.out.println(new String(response.getBytes(), "UTF8"));
    writer.close();
    reader.close();
} catch (MalformedURLException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.297362 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO