com.alibaba.fastjson.JSONException: unclosed string : w

rks48beu  于 2021-11-27  发布在  Java
关注(0)|答案(2)|浏览(973)

String aa = "{"required":true, "regex":"([\w-]+.)+[\w-]+(/[\w-./?%&=]*)?"}";
System.out.println(aa);
Map<String,Object> ruleMap = JsonUtil.fromJson(aa, LinkedHashMap.class);

qmb5sa22

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",""));

7cwmlq89

7cwmlq892#

\w在json里不合法,应该是\\w

相关问题