我需要在更高的环境中删除不需要的日志,以便优化日志记录器,因此需要从字符串中删除json或XML有效负载。
String jsonString= "This is jsonstring:{\"name\":\"xyz",\"address\":\"pqr\"}";
String xmlString= "This is xmlString not able to convert in code format of XML content:
<customer>John Smith</customer>";
尝试使用Jackson库与JSON似乎工作,但我需要以这样一种方式集成,通过检查条件,如XML或JSON,然后可以删除负载和设置空值。期待您的帮助。
int i= str.indexOf("{");
JsonNode jsonNode = new ObjectMapper().readTree(str.substring(i));
ObjectNode object = (ObjectNode)jsonNode;
object.removeAll();
1条答案
按热度按时间yshpjwxd1#
根据你的两个例子,它应该看起来像这样:
测试: