我使用了一个 api,它以 XML(以下格式)而不是 JSON 给出结果。
<soapenv:Envelope >
<soapenv:Header/>
<soapenv:Body>
<p444:DetailsResult>
<Policy>
<RenewalEligibility>YES</RenewalEligibility>
<ContCovBenEligibility>NO</ContCovBenEligibility>
<Client>
<FirstName>Pradeep</FirstName>
<LastName>Chaudhary</LastName>
<GenderCode>1</GenderCode>
<SmokerFlag>0</SmokerFlag>
<MaritalStatusCode>0</MaritalStatusCode>
</Client>
</Policy>
<WebAdress xsi:nil="true"/>
</p444:PolicyDetailsResult>
</soapenv:Body>
</soapenv:Envelope>
我使用像这样的 xmlToJson 方法将上述 xml 转换为 JSON。
让 jsonText = JSON.stringify(this.xmlToJson(xml)); 让 jsoParseData = JSON.parse(jsonText);
我得到了以下格式的结果。
{
"soapenv:Envelope": {
"soapenv:Body": {
"p444:DetailsResult": {
"Policy": {
"RenewalEligibility": "YES",
"ContCovBenEligibility": "NO",
"Client": {
"FirstName": "Pradeep",
"LastName": "Chaudhary",
"GenderCode": "1",
"SmokerFlag": "0",
"MaritalStatusCode": "0"
}
}
}
}
}
}
但我想以以下格式提取到 JSON
"Header": null,
"Body": {
"PolicyDetailsResult": {
"Policy": {
"RenewalEligibility": "YES",
"ContCovBenEligibility": "NO",
"Client":{
"FirstName":"Pradeep",
"LastName":"Chaudhary",
"GenderCode":"1",
"SmokerFlag":"0",
"MaritalStatusCode":"0",
}
}
}
}
提前致谢