package com.example.mybatiscodehelper.demo;

import org.springframework.boot.configurationprocessor.json.JSONObject;

import java.io.*;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
* @Author huangyanchang
* @Date 2022/9/8 22:29
*
* 用于将idNO=xxxx, userName=廖x文, cardNO=xxxxx, mobilePhone=xxxx, payChannelCode=ybp_1
* 成{"idNO":"xxxx","userName":"廖x文","cardNO":"xxxxx","mobilePhone":"xxxx","payChannelCode":"ybp_1"}
*
* @Version 1.0
*/
public class SpringConvertMap {

/**
* 用于将idNO=xxxx, userName=廖x文, cardNO=xxxxx, mobilePhone=xxxx, payChannelCode=ybp_1
* 转成{"idNO":"xxxx","userName":"廖x文","cardNO":"xxxxx","mobilePhone":"xxxx","payChannelCode":"ybp_1"}
* */
public static void main(String[] args) {
String str = "UserTest(id=1, name=hy)";
int i = str.indexOf("(");
char c = str.charAt(i);
String substring = str.substring(i + 1, str.lastIndexOf(")"));
System.out.println("subString: " + substring);
String lineTxt = readFile();
Map map = StringConvertMap(lineTxt);
System.out.println(new JSONObject(map));
System.out.println(substring);
}

private static String readFile() {
String lineTxt = "";
String str = "";
File file = new File("D:\\work\\demo\\src\\main\\resources\\log.txt");
if (file != null) {
try (InputStreamReader reader = new InputStreamReader(new FileInputStream(file), "utf-8")){
BufferedReader bufferedReader = new BufferedReader(reader);
if (file.isFile() && file.exists()) {
while ((lineTxt = bufferedReader.readLine()) != null) {
System.out.println("lineTex: " + lineTxt);
str = lineTxt;
}
} else {
System.out.println("读取文件出错!!");
}
} catch (IOException e) {
e.printStackTrace();
}
}
return str;
}

private static Map StringConvertMap(String toString) {
HashMap<Object, Object> map = new LinkedHashMap<>();
if (toString.contains("(") && toString.contains(")")) {
toString = toString.replace("(", "{");
toString = toString.replace(")", "}");
}
toString.trim();
String[] split = toString.split(",");
for (int i = 0; i < split.length; i++) {
String[] split1 = split[i].split("=");
map.put(split1[0], split1[1]);
}
return map;
}
}

最新文章

  1. java报表工具FineReport的公式编辑框的语法简介
  2. Linux上安装五笔
  3. H2 database 行相加-行列转换
  4. Delphi XE5 如何设计并使用FireMonkeyStyle(转)
  5. SQLite入门与分析(四)---Page Cache之事务处理(1)
  6. memcached 在windows下安装及启动
  7. iOS开发 - 不进入待机(屏幕保持唤醒)---UIApplication学习
  8. Keil伪指令
  9. Emmet 语法探析
  10. 一个简单的样例看明确怎样利用window.location.hash实现ajax操作时浏览器的前进/后退功能
  11. Python:Python学习总结
  12. Unity跨平台原理
  13. remoteViews简介
  14. 列举spark所有算子
  15. django-rest-framework-jwt
  16. java的引用
  17. JS笔记(二):对象
  18. web.net用户控件
  19. Nginx作为反向代理服务器
  20. Mysql中的auto_increment

热门文章

  1. STM32F4寄存器初始化:PWM输出
  2. element plus + vue3表单第一次数据未清空的bug问题解决
  3. 郁金香 中级班 2.c++的基类和派生类
  4. JZOJ 2474. 【GDKOI 2021普及组DAY2】我的世界
  5. (三) Mysql 之MVCC
  6. JavaScript之异步编程
  7. linux kali 换源细节
  8. RT-Thread Studio使用——创建工程并配置外部时钟(转)
  9. 四种语言刷算法之47. 全排列 II
  10. UVM——通过一个简单的testbench来了解UVM组件的phase执行顺序