Volley JsonObjectRequest 的编码不正确 API - UTF-8

Encoding not correct with Volley JsonObjectRequest API - UTF-8

我的 API (nodejs) 和我的 android 客户端之间存在关于编码的问题。

Android 截击请求:

JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.GET, tmpUrl, null, new Response.Listener<JSONObject>() {
                        @Override
                        public void onResponse(JSONObject response) {
                            Log.e("TEST", "" + response.toString());
                        }
                    },
                    new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError error) {
                            error.printStackTrace();
                        }
                    }
            );
queue.add(jsObjRequest);

Header 我的 GET 请求:

content-type → application/json; charset=utf-8

测试日志:

TEST: {"announces":[{"_id":"56360bca8c9356a3289788aa","title":"marché", ....

正常标题应该是“marché”,但它不起作用..

问题出在哪里? API 或 Android 客户端?我在不同的项目中使用了这个 volley 库,一切正常...

两者都不一定是错的,它们只是不匹配。 您的客户假设结果的编码是 UTF-8,但显然不是。

所以,你有两个选择 - 要么强制 nodejs 为 return UTF-8,要么弄清楚它是什么编码 returning,然后在 Android 端使用它.