import org.json.JSONObject;
import org.json.XML;
// xml解析后的JSON
JSONObject parseJSON;
try {
parseJSON = XML.toJSONObject(xmlStr).getJSONObject("BaseLine"); //xmlStr传入的xml格式字符串,BaseLine xml中的顶层节点
} catch (JSONException e) {
logger.error("XML格式错误******" + e.getMessage() + "******");
return "N-" + e.getMessage();
}
XML参考示例:
<?xml version="1.0" encoding="GB2312"?>
<BaseLine>
<Number>0000073676</Number>
<Name>JC-xxx-S-20190411</Name>
<State>RELEASED</State>
<LastModified>2019/04/11 00:43</LastModified>
<Product>D/代号-名称(S阶段)</Product>
<Type>MBOM</Type>
</BaseLine>