需要处理的字符串
[{columnDisplaySize=8, columnName=WARD_CODE, columnTypeName=varchar}, {columnDisplaySize=11, columnName=BED_NO, columnTypeName=int},[{columnDisplaySize=8, columnName=WARD_CODE, columnTypeName=varchar}, {columnDisplaySize=11, columnName=BED_NO, columnTypeName=int}]]
需求
需要在等号两边的字符串都加上双引号,并将等号转换成冒号,,使其成为标准的JSON字符串.
解决方案
String str="[{columnDisplaySize=8, columnName=WARD_CODE, columnTypeName=varchar}, {columnDisplaySize=11, columnName=BED_NO, columnTypeName=int}]";
String strS="(\\w+)\\s*=\\s*(\\w+)";
String strresult=str.replaceAll(strS,"\"$1\":\"$2\""); System.out.println(strresult