<?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> <soapenv:Header xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/> <soapenv:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ESB_CS_QRY_USED_RESUSED_001 xmlns="http://esb-sc. yw.zj.chinamobile.com"> <reqXml xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"> <![CDATA[ <?xml version="1.0" encoding="UTF-8"?><RESP_PARAM><PUB_INFO><RETURN_RESULT>0</RETURN_RESULT><RETURN_DESC>操作成功</RETURN_DESC><OSB_SERIAL_NO>gateway-app-zt^16846071330000000001</OSB_SERIAL_NO></PUB_INFO><BUSI_INFO><GPRS_INFO><GPRS_IN>0</GPRS_IN><GPRS_OUT>0</GPRS_OUT><GPRS_OTHER>0</GPRS_OTHER><GPRS_DURA>0</GPRS_DURA><GPRS_FEE>0</GPRS_FEE></GPRS_INFO><MMS_INFO><MMS_AMOUNT>0</MMS_AMOUNT></MMS_INFO><SMS_INFO><TOTAL_MSG_NUM>15</TOTAL_MSG_NUM><OUT_MSG_NUM>0</OUT_MSG_NUM><INNER_MSG_NUM>0</INNER_MSG_NUM><MEN_MSG_NUM>15</MEN_MSG_NUM></SMS_INFO></BUSI_INFO></RESP_PARAM>]]> </reqXml> </ESB_CS_QRY_USED_RESUSED_001> </soapenv:Body> </soapenv:Envelope>
时间: 2023-11-16 16:21:45 浏览: 194
好的,以下是将该返回内容转换为 JSON 的方法:
1. 点击 Postman 中响应 Body 旁边的 `Code` 按钮,在弹出的对话框中选择 `Node.js - request` 代码片段。
2. 将代码片段中的 `body` 变量赋值为返回内容,即替换下面代码中的 `XMLRESPONSE`:
```
var body = `<xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<soapenv:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ESB_CS_QRY_USED_RESUSED_001 xmlns="http://esb-sc. yw.zj.chinamobile.com">
<reqXml xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<![CDATA[
<?xml version="1.0" encoding="UTF-8"?><RESP_PARAM><PUB_INFO><RETURN_RESULT>0</RETURN_RESULT><RETURN_DESC>操作成功</RETURN_DESC><OSB_SERIAL_NO>gateway-app-zt^16846071330000000001</OSB_SERIAL_NO></PUB_INFO><BUSI_INFO><GPRS_INFO><GPRS_IN>0</GPRS_IN><GPRS_OUT>0</GPRS_OUT><GPRS_OTHER>0</GPRS_OTHER><GPRS_DURA>0</GPRS_DURA><GPRS_FEE>0</GPRS_FEE></GPRS_INFO><MMS_INFO><MMS_AMOUNT>0</MMS_AMOUNT></MMS_INFO><SMS_INFO><TOTAL_MSG_NUM>15</TOTAL_MSG_NUM><OUT_MSG_NUM>0</OUT_MSG_NUM><INNER_MSG_NUM>0</INNER_MSG_NUM><MEN_MSG_NUM>15</MEN_MSG_NUM></SMS_INFO></BUSI_INFO></RESP_PARAM>
]]>
</reqXml>
</ESB_CS_QRY_USED_RESUSED_001>
</soapenv:Body>
</soapenv:Envelope>`;
```
3. 在代码片段中添加以下代码来将 XML 转换为 JSON:
```
var parseString = require('xml2js').parseString;
parseString(body, function (err, result) {
console.log(JSON.stringify(result));
});
```
4. 点击 `Send` 按钮,运行代码片段并在控制台中查看转换后的 JSON 结果。
以上就是将该返回内容转换为 JSON 的方法。希望对您有所帮助!
阅读全文