拉取微信用户信息乱码解决办法

  |   0 评论   |   0 浏览

问题描述

在做拉取微信用户的时候,所有的中文字都是乱码。好郁闷。查找了半天发现微信返回的编码格式是ISO-8859-1,我们需要用ISO-8859-1接收,然后再转成UTF-8。不做转化直接保存就是乱码的。

代码如下:

try {
            if (StringUtils.isEmpty(url)) {
                return null;
            }
            String resStr = doPost(url, postForm, 0, contentType);
            if(resStr != null) {
                resStr = new String(resStr.getBytes("ISO-8859-1"), "UTF-8");
            }
            return JSON.parseObject(resStr,clazz);
        }catch (Exception e){
            throw new IOException(e);
        }

这样。我的问题解决了。


标题:拉取微信用户信息乱码解决办法
作者:guobing
地址:http://www.guobingwei.tech/articles/2016/10/18/1476796696496.html