zoukankan      html  css  js  c++  java
  • 关于字符编码的问题

    在一个activity里面有一个文本输入框,我在后台通过
    EditText et_username = (EditText) findViewById(R.id.username);
    String username = new String(et_username.getText().toString());
    这样拿到的字符串不是utf-8.我尝试这样:
    username = new String(et_username.getText().toString().getBytes("UTF-8"));
    拿到的字符串依然不是utf-8希望牛人赐教怎么能够从activity获取utf-8字符集的字符串?

    String keyword = new String(keyword_EditText.getText()
                                    .toString().getBytes("UTF-8"));
                            keyword = URLEncoder.encode(keyword_EditText.getText().toString());

    httpost = new HttpPost(API_DefaultURL.replace("{0}", _page));
                    httpost.setHeader("Content-Type", "text/plain; charset=utf-8");
                    StringEntity entity = new StringEntity(strdata);
                    httpost.setEntity(entity);
                    DefaultHttpClient client = new DefaultHttpClient();
                    HttpResponse response = client.execute(httpost);
                    source = EntityUtils.toString(response.getEntity(), "UTF-8");

  • 相关阅读:
    About Me
    洛谷 P2633 Count on a tree
    【题解】牛客编程巅峰赛S1赛季第1场
    洛谷 P4132 [BJOI2012]算不出的等式
    洛谷 P5970 [POI2016]Nim z utrudnieniem
    DP没入门就入土
    洛谷 P4042 [AHOI2014/JSOI2014]骑士游戏
    洛谷 P3592 [POI2015]MYJ
    51Nod 1683 最短路
    51Nod 1327 棋盘游戏
  • 原文地址:https://www.cnblogs.com/myphoebe/p/2314859.html
Copyright © 2011-2022 走看看