【发布时间】:2018-08-26 19:03:39
【问题描述】:
我需要帮助来将此 XML 消息解析为 JSON 结构。我尝试使用XmlMapper 使用 Jackson 库。它不断给出解析错误。我需要解析出多余的字符吗?
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<ns2:GetLineItemDetailResponse xmlns:ns2="http://schema.tmt.com/transactionlineitemdetail/loyalty/v1">
<GetLineItemDetailResult>
<Coupons>
<Coupon>
<CouponType>sim_default_CouponType</CouponType>
<CouponNumber>sim_default_CouponNumber</CouponNumber>
<LineNumber>0</LineNumber>
<Amount>0</Amount>
</Coupon>
</Coupons>
<Tenders>
<Tender>
<TenderCode>sim_default_TenderCode</TenderCode>
<Amount>0</Amount>
<RedemptionID>0</RedemptionID>
</Tender>
</Tenders>
<LineItems>
<LineItem>
<LineNumber>0</LineNumber>
<Type>1</Type>
<Quantity>0</Quantity>
<TotalTax>0</TotalTax>
<UPC>sim_default_UPC</UPC>
<UnitPrice>0</UnitPrice>
<ExtendedPrice>0</ExtendedPrice>
<TotalPrice>0</TotalPrice>
<OriginalRFN xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<OriginalOrderID xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<IneligForRedeem>false</IneligForRedeem>
<RX>
<Days>0</Days>
<ThirtyTo90>false</ThirtyTo90>
<GovtFunded>1970-01-01T00:00:00</GovtFunded>
<RXType>NEW</RXType>
<PartialFill>false</PartialFill>
<ImmunInd>false</ImmunInd>
<ImmunType>sim_default_ImmunType</ImmunType>
<RXEligibleInd>false</RXEligibleInd>
</RX>
<ns3:UPCDescription xmlns:ns3="http://www.epsilon.com/webservices/">sim_default_UPCDescription</ns3:UPCDescription>
</LineItem>
</LineItems>
<Redemption>
<AwardID>0</AwardID>
<Amount>0</Amount>
<Points>0</Points>
</Redemption>
</GetLineItemDetailResult>
</ns2:GetLineItemDetailResponse>
我试过这个:
XmlMapper xmlMapper = new XmlMapper();
JsonNode node = xmlMapper.readTree(xml.getBytes());
ObjectMapper jsonMapper = new ObjectMapper();
String json = jsonMapper.writeValueAsString(node);
System.out.println(json);
但是一直报错
Misshaped close tag at 2299 [character 91 line 52]
【问题讨论】:
-
您看到的错误是什么?
-
我已经尝试过解决方案,但没有奏效。
-
在 2299 [字符 91 第 52 行] 处的闭合标签形状错误
-
当我从文件中读取 XML 时,它适用于我。 XML 只有 50 行。您如何将 XML 读入您的程序?