zk中文乱码问题
Posted wuxun1997
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了zk中文乱码问题相关的知识,希望对你有一定的参考价值。
之前讲了怎么把数据导入到zookeeper(见zookeeper事件监听),本机win10的zookeeper展示没问题,到了linux上就出现乱码了:
<<<2018-09-29 09:14:54,905| DEBUG | ZKUtil.getServiceAccessCompany() invoke getServiceAccessCompany !{"11111":{"mchId":"11111","mchName":"??????","mchType":"11 1","spId":"AAAAA","key":"BBBBB","remark":"??????"},"22222":{"mchId":"22222","mchName":"????????","mchType":"22","spId":"CCCCC","key":: "DDDDD","remark":"???????zk??"},"33333":{"mchId":"33333","mchName":"????","mchType":"33","spId":"EEEEE","key":"FFFFF","remark":"????"}}
| com.wlf.utils.ZKUtil>>>
想了一下,数据是作为json格式导入到zk的,json说白了就是字符串,那么是否我要指定一下编码格式?试了下:
companyMap.put(sac.getMchId(), getJson(sac).getBytes("utf-8"));
结果报错依旧。那么我只针对中文的字段来指定编码格式呢?再试下:
sac.setMchName(new String("广东省公司".getBytes("utf-8"), "utf-8"));
也不行。把两者结合起来,都指定,这次可以了:
<<<2018-09-29 11:58:02,553| DEBUG | ZKUtil.getServiceAccessCompany() invoke getServiceAccessCompany !{"11111":{"mchId":"11111","mchName":"广东省公司","mchType":"11","spId":"AAAAA","key":"BBBBB","remark":" "},"22222":{"mchId":"22222","mchName":"江苏省公司","mchType":"22","spId":"CCCCC","key":"DDDDD","remark":" "},"33333":{"mchId":"33333","mchName":"北京","mchType":"33","spId":"EEEEE","key":"FFFFF","remark":" "}} | com.wlf.utils.ZKUtil>>>
以上是关于zk中文乱码问题的主要内容,如果未能解决你的问题,请参考以下文章