JSONObject jsonObject = new JSONObject(); 
  jsonObject.put("userName","alex"); 
  String s = jsonObject.toJSONString(); 
  System.out.println(s); 
   
  // 定义图片宽度 
  int width = 200; 
  // 定义图片高度 
  int height= 200; 
   
  Map<EncodeHintType,Object> hints = new HashMap<EncodeHintType, Object>(); 
  hints.put(EncodeHintType.CHARACTER_SET,"UTF-8"); 
  BitMatrix bitMatrix = new MultiFormatWriter().encode(s, BarcodeFormat.QR_CODE,width,height,hints); 
   
  String filePath = "D://"; 
  String fileName = "qrCode.jpg"; 
   
  // 定义路径对象 
  Path path = FileSystems.getDefault().getPath(filePath,fileName); 
  MatrixToImageWriter.writeToPath(bitMatrix,"jpg",path); 
   
  System.out.println(path); 
  
 |