Android json utf8

2

Good afternoon! I have a class that imports json data, but some characters are not recognized, I have to apply utf8 on them but I am not getting below the function that imports the data.

public void carregarCategorias() {
    JsonArrayRequest movieReq = new JsonArrayRequest(url,
            new Response.Listener<JSONArray>() {
                @Override
                public void onResponse(JSONArray response) {

                    for (int i = 0; i < response.length(); i++) {
                        try {
                            JSONObject obj = response.getJSONObject(i);
                            categoria = new Categoria();
                            categoria.setIcone(obj.getString("icone"));
                            categoria.setCategoria(obj.getString("categoria"));
                            categoria.setEmpresas(obj.getString("empresas"));
                            categoriaList.add(categoria);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                    // Notificando adaptador lista sobre as alterações de dados
                    // Para que ele torna a exibição de lista com dados atualizados
                    adapter.notifyDataSetChanged();

                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
        }
    });
    AppController.getInstance().addToRequestQueue(movieReq);
    itemClick();
}

Please, somebody help me!

    
asked by anonymous 08.07.2016 / 21:06

1 answer

0

I've faced this problem once, and I've resolved it by converting the string to bytes in the ISO-8859-1 standard and then creating a new String. I created a method that returns the String in UTF-8:

public static RetornaStringUtf8JSon(JSONObject obj, String key) {
    return new String(obj.getString(key).getBytes("ISO-8859-1"), "UTF-8"); 
}

Reference: link

    
08.07.2016 / 21:25