我没有得到任何线索,为什么特殊字符ÅÖÄ在使用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发送它,但我没有得到问题?
答案 0 :(得分:0)
试试这个
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);
如果它适合你,请将答案标记为正确。