-3
,"Metadata":{"ModifiedDate":"Thu Dec 10 20151046","CreatedDate":"Thu Dec 10 2015 10:46:30 GMT+0530 (IST)","HiddenRule":"[{\"text\":\"\",\"data_type\":\"operator\",\"internal_name\":\"\"},{\"text\":\"Gender\",\"data_type\":\"String\",\"internal_name\":\"gender\",\"class\":\"Open\"},{\"text\":\"\",\"data_type\":\"operator\",\"internal_name\":\"\"},{\"text\":\"==\",\"data_type\":\"operator\",\"internal_name\":\"==\",\"class\":\"Oper\"},{\"text\":\"\",\"data_type\":\"operator\",\"internal_name\":\"\"},{\"text\":\"\\\"sd\\\"\",\"data_type\":\"operator\",\"internal_name\":\"\\\"sd\\\"\",\"class\":\"Cons\"},{\"text\":\"\",\"data_type\":\"operator\",\"internal_name\":\"\"}]"}
試圖搜索的「元數據」對象,在JSON字符串,並用空白替換它。基本上從JSON字符串中刪除的對象。 ,\ 「Metadata」[a-zA-Z0-9:{}「,+()[] \ _ == ] [}]。但在JAVA程序編譯時,現在所面臨的例外,
Exception in thread "main" java.util.regex.PatternSyntaxException: Unclosed character class near index 41
,"Metadata"[a-zA-Z0-9:{}" ,+()[]\_==*]*[}]
^
at java.util.regex.Pattern.error(Pattern.java:1924)
at java.util.regex.Pattern.clazz(Pattern.java:2493)
at java.util.regex.Pattern.sequence(Pattern.java:2030)
at java.util.regex.Pattern.expr(Pattern.java:1964)
at java.util.regex.Pattern.compile(Pattern.java:1665)
at java.util.regex.Pattern.<init>(Pattern.java:1337)
at java.util.regex.Pattern.compile(Pattern.java:1022)
at java.lang.String.replaceAll(String.java:2162)
at temp.main(temp.java:20)
String str=",\"Metadata\":{\"ModifiedDate\":\"Thu Dec 10 20151046\",\"CreatedDate\":\"Thu Dec 10 2015 10:46:30 GMT+0530 (IST)\",\"HiddenRule\":\"[{\"text\":\"\",\"data_type\":\"operator\",\"internal_name\":\"\"},{\"text\":\"Gender\",\"data_type\":\"String\",\"internal_name\":\"gender\",\"class\":\"Open\"},{\"text\":\"\",\"data_type\":\"operator\",\"internal_name\":\"\"},{\"text\":\"==\",\"data_type\":\"operator\",\"internal_name\":\"==\",\"class\":\"Oper\"},{\"text\":\"\",\"data_type\":\"operator\",\"internal_name\":\"\"},{\"text\":\"\\\"sd\\\"\",\"data_type\":\"operator\",\"internal_name\":\"\\\"sd\\\"\",\"class\":\"Cons\"},{\"text\":\"\",\"data_type\":\"operator\",\"internal_name\":\"\"}]\"}";
String regexes = ",\"Metadata\"[a-zA-Z0-9:{}\" ,+()[]\\_==*]*[}]";
System.out.println(str.replaceAll(regexes, "Hi!!!"));
這就是你得到的與正則表達式解析JSON。 – Mena