private static Pattern pattern = Pattern.compile("[\w[^\[\],{}]]+");
public static String findJsonVal(String key, String json){
if (StringUtils.isEmpty(json)) {
return null;
}
Map map = new HashMap();
Matcher m = pattern.matcher(json.replaceAll("'|"", ""));
String[] strArr = null;
while (m.find()) {
strArr = m.group().split(":");
if(strArr.length == 2){
map.put(strArr[0].trim(), strArr[1].trim());
}
}
return (String) map.get(key);
}
public static void main(String[] args) {
String json = "{"aa":"aa", "bb":"bb"}";
String val = findJsonVal("aa", json);
System.out.println(val);
}
输出:aa



