0

I am trying to get a json from my server to my android through java. I have written the json using my C# app, and checked in Sublime 2, all was fine, uploaded to server, and downloaded back, retried to open, and all was fine again. But when i do the same on android, i get some weird characters. For example, every letter with accent becomes '?'. This is the code i m using to download

        RequestQueue queue = Volley.newRequestQueue(context);
        StringRequest request = new StringRequest(Request.Method.GET, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                            Toast.makeText (MyApplication.getAppContext(), response, Toast.LENGTH_LONG).show();
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
            }
        });
        queue.add(request);

I have also tried using this code:

new String(pangtee.getString("body").getBytes("ISO-8859-1"), "UTF-8");

but neither this does the work properly.

I have seen this question: StackOverflow, but this uses php, do i have to write in php?, isn't there any way without it? I'm C# and Java dev, it will be my very first time on php.

This is an example of the file it has to download.

{
    "char1": "òàùèé",
    "char2": "ò"
}

The response contains some times '?', some other times '�', and some other times other characters, like è => "é"; ì => "ì"

Community
  • 1
  • 1
Blue Cat
  • 1
  • 1
  • 1
    We have no clue what the response looks like, including what content encoding it specifies. – Jon Skeet Jul 05 '15 at 19:12
  • It's recommended not to put accented letters etc. in JSON but rather their unicode escape equivalent. That will help avoiding such problems completely. If you don't, it's important to publish the data in the appropriate character set (UTF-8) and the mime type shoud be `application/json`. – RealSkeptic Jul 05 '15 at 19:27
  • i have tried converting it to the equivalent unicode escape, and it does the work, the only problem is that i m not able to convert all the characters. i got it working only the UTF8 chars, so the single chars characters. for those who have 2 or 4, i have no idea to convert. this is the code i m using: http://hastebin.com/ovoritahuy.coffee – Blue Cat Jul 06 '15 at 15:21
  • @RealSkeptic how does Google Chrome convert the UTF files? i have tried opening a file which was containing some special character, which Google Chrome changed into splitted 2, 3, or 4 characters, copying that, and using the source i have linked in the previous comment, it's possible to achieve the target. (ò => ò => \u00c3\u00b2) – Blue Cat Jul 06 '15 at 15:57
  • I'm not sure exactly what you are talking about. Comments are not a proper place for this. If you have additional information - especially code, which *should not* be in outside links - please add it to your question with an explanation. – RealSkeptic Jul 06 '15 at 16:30

0 Answers0