如何解决我如何遍历 postman 中的以下 xml 响应以使用循环实现所有大陆?
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<m:listofContinentsByNameResponse xmlns:m="http://www.oorsprong.org/websamples.countryinfo">
<m:listofContinentsByNameResult>
<m:tContinent>
<m:sCode>AF</m:sCode>
<m:sName>Africa</m:sName>
</m:tContinent>
<m:tContinent>
<m:sCode>AN</m:sCode>
<m:sName>Antarctica</m:sName>
</m:tContinent>
<m:tContinent>
<m:sCode>AS</m:sCode>
<m:sName>Asia</m:sName>
</m:tContinent>
<m:tContinent>
<m:sCode>EU</m:sCode>
<m:sName>Europe</m:sName>
</m:tContinent>
<m:tContinent>
<m:sCode>OC</m:sCode>
<m:sName>Ocenania</m:sName>
</m:tContinent>
<m:tContinent>
<m:sCode>AM</m:sCode>
<m:sName>The Americas</m:sName>
</m:tContinent>
</m:listofContinentsByNameResult>
</m:listofContinentsByNameResponse>
</soap:Body>
</soap:Envelope>
解决方法
var jsonObject = xml2Json(pm.response.text());
jsonObject['soap:Envelope']['soap:Body']['m:ListOfContinentsByNameResponse']['m:ListOfContinentsByNameResult']['m:tContinent'].forEach((a)=>console.log(a['m:sName']))
使用xml2json将xml转为json
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。