使用net.sf.json包将xml字符串转为JSONObject:
引入maven依赖:
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<groupId>xom</groupId>
<artifactId>xom</artifactId>
<version>1.2.5</version>
</dependency>
Java代码:
public static void main(String[] args) throws Exception {
String xmlString = "<informations>\n" +
"<returnCode>PARAMETER_ERROR</returnCode>\n" +
"<returnMessage>支付的唯一识别号必填!</returnMessage>\n" +
"</informations>";
XMLSerializer xmlSerializer = new XMLSerializer();
String resutStr = xmlSerializer.read(xmlString).toString();
JSONObject jsonObject = JSONObject.fromObject(resutStr);
}
版权声明:本文为qq_36076449原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。