使用XML.toJSONObject(xml)
<root>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>LATEST</version>
</dependency>
</dependencies>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>LATEST</version>
</dependency>
</dependencies>
</root>
,结果是
{"root":{"dependencies":[{"dependency":[{"groupId":"com.fasterxml.jackson.core","artifactId":"jackson-annotations","version":"LATEST"},{"groupId":"com.fasterxml.jackson.core","artifactId":"jackson-core","version":"LATEST"},{"groupId":"com.fasterxml.jackson.core","artifactId":"jackson-databind","version":"LATEST"}]},{"dependency":{"groupId":"com.fasterxml.jackson.core","artifactId":"jackson-annotations","version":"LATEST"}}]}}
at dependencies [0]依赖项将在数组中转换,即[OK]
但依赖[1]依赖将在对象中转换,即创建问题以在pojo类中使用jackson进行解析。