抱歉我的英文。我有方法解码字符串,但在控制台中我有warn
。我得到代码字符串base64,我需要解码它的字符串。
06-11 06:49:40.557: W/EGL_genymotion(1611): eglSurfaceAttrib not implemented
06-11 06:49:41.041: W/System.err(1611): java.io.IOException: Bad Base64 input character decimal 208 in array position 0
06-11 06:49:41.041: W/System.err(1611): at com.motottaxi24user.Base64.decode(Base64.java:1201)
06-11 06:49:41.077: W/System.err(1611): at com.motottaxi24user.Base64.decode(Base64.java:1122)
06-11 06:49:41.077: W/System.err(1611): at com.motottaxi24user.User.decodeString(User.java:240)
06-11 06:49:41.097: W/System.err(1611): at com.motottaxi24user.User$NewsAsynkTask.doInBackground(User.java:200)
06-11 06:49:41.137: W/System.err(1611): at com.motottaxi24user.User$NewsAsynkTask.doInBackground(User.java:1)
06-11 06:49:41.141: W/System.err(1611): at android.os.AsyncTask$2.call(AsyncTask.java:287)
06-11 06:49:41.181: W/System.err(1611): at java.util.concurrent.FutureTask.run(FutureTask.java:234)
06-11 06:49:41.197: W/System.err(1611): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
06-11 06:49:41.213: W/System.err(1611): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
06-11 06:49:41.217: W/System.err(1611): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
06-11 06:49:41.237: W/System.err(1611): at java.lang.Thread.run(Thread.java:856)
06-11 06:49:41.281: W/System.err(1611): java.io.IOException: Bad Base64 input character decimal 58 in array position 2
我的方法:
public String decodeString(String line) {
byte[] tmp2;
String val2 = null;
try {
tmp2 = Base64.decode(line);
val2 = new String(tmp2, "UTF-8");
} catch (IOException e) {
e.printStackTrace();
}
return val2;
}
答案 0 :(得分:1)
错误消息sais,在第二个位置的字符串中是代码为58的字符。这是冒号:在base64中不允许。所以,检查你的输入
答案 1 :(得分:0)
尝试这样的事情:
public String decodeString(String line) {
byte[] tmp2;
String val2 = null;
try {
tmp2 = Base64.decode(line.getBytes());
val2 = new String(Base64.encode(tmp2), "UTF-8");
} catch (IOException e) {
e.printStackTrace();
}
return val2;
}