【发布时间】: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