【发布时间】:2022-10-05 15:08:15
【问题描述】:
我有以下肥皂回应
<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">
<soap:Body>
<ns2:confirmPayer_10Response xmlns:ns2=\"http://v1.ws.provider.acp.com/\">
<return>
<KeyValues>
<Key>MICROFILM_NUMBER</Key>
<Data>71111112236100141977490</Data>
</KeyValues>
<KeyValues>
<Key>USER_TOKEN</Key>
<Data>hpuser</Data>
</KeyValues>
<KeyValues>
<Key>PASSWORD_TOKEN</Key>
<Data>hpuser+22**</Data>
</KeyValues>
</return>
</ns2:confirmPayer_10Response>
</soap:Body>
</soap:Envelope>
如何将此响应转换为 json,如下所示
{
\"MICROFILM_NUMBER\" : \"71111112236100141977490\",
\"USER_TOKEN\" : \"hpuser\",
\"PASSWORD_TOKEN\" : \"hpuser+22**\"
}
-
1. 从 SOAP 正文中获取 XML 答案。 2. 遍历 KeyValues。 3. 对于每个键值,将其存储到 Map 4. 将 Map 序列化为 Json,您将得到您想要的。
标签: java json xml spring-boot soap