And*_*oid 2 java base64 android
我正在使用API Level 7(Android 2.1)构建应用程序,我需要解码由服务器接收的字符串,该字符串使用Base64编码.我知道Base64库包含在Android 2.2中,这就是为什么我直接在我的项目中包含它的源代码.你可以在这里找到源代码:Base64.
所以我的问题是,当我尝试解码字符串中的Base64返回此:BASE 64 : [B@46392d10.
如果我运行服务器发送给我的在线base64解码器的代码我得到这个: le":"en_US","id":2,"error_code":6003,"error_string":"Unsupported Client Version"}
这是我正在使用的代码:
HttpResponse response = httpclient.execute(httppost);
Log.v("Response ","Status line : "+ response.getStatusLine().toString());
String responseBody = EntityUtils.toString(response.getEntity()); //response
Log.v("Response ","Response : "+ responseBody);
String objectIdentificator = responseBody.substring(0,32);
Log.v("Response ","Object Identificator (LONGINT) : "+ objectIdentificator);
String type = responseBody.substring(33,36);
Log.v("Response ","TYPE (UNSIGNED BYTE) : "+ type);
String operation = responseBody.substring(37,40);
Log.v("Response ","OPERATION (UNSIGNED BYTE) : "+ operation);
String objectId = responseBody.substring(41, 73);
Log.v("Response ","UID (CHAR, length 32) : "+ objectId);
String id = responseBody.substring(74, 106);
Log.v("Response ","ID (LONGINT) : "+ id);
String size = responseBody.substring(107,139);
Log.v("Response ","Data Size (LONGINT) : "+ size);
String hash = responseBody.substring(140,172);
Log.v("Response ","Data Hash (CHAR, length 32 : "+ hash);
String dType = responseBody.substring(173,176);
Log.v("Response ","Data Type (UNSIGNED BYTE) : "+ dType);
String data = responseBody.substring(177, responseBody.length());
Log.v("Response ","Data (CHAR, any length, in BASE64) : "+ data);
String first = Base64.decode(data, Base64.DEFAULT).toString();
Log.v("Response ","BASE 64 : "+ first);
Run Code Online (Sandbox Code Playgroud)
任何建议如何解决?
Joa*_*uer 12
你的问题与此无关Base64.
该Base64班正确返回一个byte[]包含数据.你叫toString()上byte[]这确实不使用内容的byte[],但只有它的identityHashCode().
你想这样做,而不是你转换byte[]成String给予正确的编码:
byte[] bytes = Base64.decode(data, Base64.DEFAULT);
String string = new String(bytes, "UTF-8");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9498 次 |
| 最近记录: |