java 微信授权后获取微信用户信息昵称乱码问题 解决

在网上找了挺久没找到解决办法啊。终于解决了,保存一份哈。便于自己以后查阅

//获取用户信息 
String getUserInfoUrl = " https://api.weixin.qq.com/sns/userinfo?access_token="+access_token+"&openid="+openid+"&lang=zh_CN"; 

URL url1 = new URL(getUserInfoUrl); 
HttpURLConnection urlConnection = (HttpURLConnection)url1.openConnection(); 

// 将返回的输入流转换成字符串 
InputStream inputStream = urlConnection.getInputStream(); 
InputStreamReader inputStreamReader = new InputStreamReader(inputStream,"UTF-8"); 
BufferedReader in = new BufferedReader(inputStreamReader); 

String jsonUserStr =in.readLine().toString(); 

out.println("jsonUserStr = "+jsonUserStr); 

// 释放资源 
inputStream.close(); 
inputStream = null; 
urlConnection.disconnect(); 

JSONObject jsonUserObject = new JSONObject(jsonUserStr);

你可能感兴趣的:(微信开发,java,乱码,微信)