字节数组与一些中文字符串

时间:2014-07-03 03:32:03

标签: android string bytearray

我正在将字节数组转换为字符串,它包含一些中文字符但我无法正确显示。我从我使用UTF-8的数据库加载它。

代码:

            String url = params[0];
            HttpClient client = new DefaultHttpClient();
            HttpResponse response;
            long fileSize = 0;
            int downloadSize = 0;
            String jsonStr = "";            

            try {
                response = client.execute(new HttpGet(url));
                StatusLine status = response.getStatusLine();
                if (status.getStatusCode() == HttpStatus.SC_OK){
                    fileSize = response.getEntity().getContentLength();

                    InputStream inputStream = response.getEntity().getContent();
                    byte[] buffer = new byte[1024];
                    int numByteRead = 0;

                    BufferedOutputStream outputStream = new BufferedOutputStream(new ByteArrayOutputStream());
                    while ( (numByteRead = inputStream.read(buffer)) > 0){
                        outputStream.write(buffer, 0, numByteRead);
                        jsonStr += new String(buffer, "UTF-8");
                        downloadSize += numByteRead;
                        Log.i(SUBTAG, "downloadSize/fileSize: "+downloadSize+"/"+fileSize);
                    }

                    Log.d(SUBTAG, "jsonStr: "+jsonStr);
                } else {
                    Log.e(SUBTAG, "connection problem : "+status.getStatusCode());
                    finish();
                }

            } catch (IOException e) {
                // TODO Auto-generated catch block
                Log.e(SUBTAG, "connection failed : "+e);
                finish();
            }

以及我得到的结果:

jsonStr: [{"user_id":"1","user_group_id":"1","user_login":"gary.ng","user_password":"LZ1dl2zN","last_login":"0000-00-00 00:00:00","last_modified":"2014-06-30 18:10:00","user_group_name":"Admin","user_group_meta":"admin","user_info_id":"1","user_company":"Garland Digital System Ltd.","user_company_business":"\u6d41\u52d5\u61c9\u7528\u7a0b\u5f0f","category_id":"7","user_company_years":"I.T.16\u5e74, \u516c\u53f85\u500b\u6708","user_experience":"Technician, \u8ce3\u96fb\u8166Sales, Game Project Designer, Programmer","user_title":"Director","user_phone":"31716517","user_mobile":"94211582","user_fax":"","user_web":"https:\/\/www.garland-digital.hk","user_address":"\u8343\u7063\u694a\u5c4b\u9053137-143\u865f9\u6a13925\u5ba4","user_photo":"","user_namecard_1":"","user_namecard_2":"","user_spouse":"\u66ab\u6642\u55ae\u8eab","user_children":"1\u500b\u990a\u5b50(\u4fdd\u826f\u5c40)","user_pets":"\u7121","user_hobby":"\u6e38\u6c34, \u505a\u7fa9\u5de5","user_interest":"\u5531K, \u8b80\u66f8, \u651d\u5f71, \u4e00\u500b\u4eba\u65c5\u884c","user_expect":"\u79d1\u6280\u6539\u8b8a\u751f\u6d3b\uff0c\u79d1\u6280\u6539\u8b8a\u793e\u6703","user_secret":"\u53c3\u52a0\u904e\u5340\u5167\u6b4c\u5531\u6bd4\u8cfd","user_success":"\u5c07\u5fc3\u6bd4\u5df1","category_name":"\u96fb\u5b50\u6280\u8853\u670d\u52d9"}].","user_company_business":"\u6d41\u52d5\u61c9\u7528\u7a0b\u5f0f","category_id":"7","user_company_years":"I.T.16\u5e74, \u516c\u53f85\u500b\u6708","user_experience":"Technician, \u8ce3\u96fb\u8166Sales, Game Project Designer, Programmer","user_title":"Director","user_phone":"31716517","user_mobile":"94211582","user_fax":"","user_web":"https:\/\/www.garland-digital.hk","user_address":"\u8343\u7063\u694a\u5c4b\u9053137-143\u865f9\u6a13925\u5ba4","user_photo":"","user_namecard_1":"","user_namecard_2":"","user_spouse":"\u66ab\u6642\u55ae\u8eab","user_children":"1\u500b\u990a\u5b50(\u4fdd\u826f\u5c40)","user_pets":"\u7121","user_hobby":"\u6e38\u6c34, \u505a\u7fa9\u5de5","user_interest":"\u5531K, \u8b80\u66f8, \u651d\u5f71, \u4e00\u500b\u4eba\u65c5

0 个答案:

没有答案