【问题标题】:Special characters Å Ö Ä showing � character using UTF-8 encoding during JSON paring Android特殊字符 Å Ö Ä 在 JSON 配对 Android 期间显示使用 UTF-8 编码的字符
【发布时间】:2014-11-19 14:59:07
【问题描述】:

我不知道为什么特殊字符 Å Ö Ä 在 JSON 配对 Android 期间使用 UTF-8 编码显示 � 字符。以下是我正在使用的代码。

    myjson.put("name", "ÅsdfÖ")); 
    entity = new StringEntity(myjson.toString()); 

    entity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"application/json; charset=utf-8"));
    HttpPost httppost=new HttpPost(URL);
    httppost.setHeader("content-Type", "application/json");
    httppost.setHeader("accept", "application/json");
    httppost.setHeader("Authorization", "token");
    httppost.setEntity(entity);

我得到的响应类似于“名称”:“sdf”,并且在后端网页中也显示相同。

虽然我使用 UTF-8 endconding 发送它,但我不知道问题出在哪里?

【问题讨论】:

  • 您正在使用 setHeader() app/json 调用覆盖内容类型。那里没有 utf8 字符集定义。
  • 检查数据库编码

标签: android json encoding utf-8


【解决方案1】:

试试这个

HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(url);

        JSONObject myjson= new JSONObject();
        myjson.put("name", "ÅsdfÖ"));

        httppost.setEntity(new StringEntity(myjson.toString(), "UTF-8"));
        httpResponse = httpclient.execute(httppost);

如果对您有用,请将答案标记为正确。

【讨论】:

    猜你喜欢
    • 2019-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-20
    • 2019-10-02
    • 2018-02-16
    相关资源
    最近更新 更多