问题:在memcache调用asyncIncr使用计数器,当计数器为1的时候,再取出来转换为数字格式报错java.lang.NumberFormatException: For input string: "1",而其他数字则没有这个问题
MemcacheUtil.asyncIncr("_loopCounter",1,1,30);
Integer loopCounter = Integer.valueOf((String) MemcacheUtil.getData("_loopCounter"));
报错如下:
java.lang.NumberFormatException: For input string: "1"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Integer.parseInt(Integer.java:580)
at java.lang.Integer.valueOf(Integer.java:766)
原因:使用StringEscapeUtils.escapeJava()将字符串“1”转换为unicode字符发现,多了很多隐藏的字符\u0000 “1\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000”
解决:将\u0000字符剔除掉之后再进行数字转换