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");

  • 相关阅读:
    Swift8-枚举Enumerations
    Swift7-闭包
    Swift6-函数
    Swift5-控制流
    Swift4-集合类型
    什么是node.js
    nodejs的安装
    环境变量的认识,,,
    shell是什么,各种shell的初步认识,适用于初学者
    exports和module.exports的区别
  • 原文地址:https://www.cnblogs.com/myphoebe/p/2314859.html
Copyright © 2011-2022 走看看