String aa = "{"required":true, "regex":"([\w-]+.)+[\w-]+(/[\w-./?%&=]*)?"}";System.out.println(aa);Map<String,Object> ruleMap = JsonUtil.fromJson(aa, LinkedHashMap.class);
qmb5sa221#
"\w" -> "\\w"in the source code will check the char '' .
change:
String aa = "{\"required\":true,\"regex\":"([\\\\w-]+\\\\.)+[\\\\w-]+(/[\\\\w-./?%&=]*)?\"}";LinkedHashMap ruleMap = JSON.parseObject(aa, LinkedHashMap.class);System.out.println(MapUtils.getString(ruleMap,"regex",""));
String aa = "{\"required\":true,\"regex\":"([\\\\w-]+\\\\.)+[\\\\w-]+(/[\\\\w-./?%&=]*)?\"}";
LinkedHashMap ruleMap = JSON.parseObject(aa, LinkedHashMap.class);
System.out.println(MapUtils.getString(ruleMap,"regex",""));
7cwmlq892#
\w在json里不合法,应该是\\w
\w
\\w
2条答案
按热度按时间qmb5sa221#
"\w" -> "\\w"
in the source code will check the char '' .
change:
String aa = "{\"required\":true,\"regex\":"([\\\\w-]+\\\\.)+[\\\\w-]+(/[\\\\w-./?%&=]*)?\"}";
LinkedHashMap ruleMap = JSON.parseObject(aa, LinkedHashMap.class);
System.out.println(MapUtils.getString(ruleMap,"regex",""));
7cwmlq892#
\w
在json里不合法,应该是\\w