我想从json字符串中删除所有"key":null
模式。
String jsonStr = "{\"a\":null,\"b\":1,\"c\":null,\"d\":5}";
System.out.println(jsonStr.replaceAll("\".*?\":null,", ""));
我期待
{"b":1,"d":5}
但结果是
{"d":5}
显然,非贪婪不适用。
我尝试使用Pattern
,Matcher
。但它也会产生相同的结果。
Pattern replace = Pattern.compile("\".*?\":null,");
Matcher matcher = replace.matcher(jsonStr);
System.out.println(matcher.replaceAll(""));