javascript - node-soap 结果是深层嵌套对象而不是普通结果
问题描述
我使用 node-soap 来请求 SOAP-API。但结果并不如我所料。如果我使用 PHP 请求相同的内容(所有 api 示例都在 php 中),它会按预期工作。但是我的应用程序/服务是用 JavaScript (ExpressJS) 编写的。
我的请求代码很简单:
var url = '...wsdl';
var args = {
Params: JSON.stringify({
User: '...',
AuthType: 'session',
AuthData: '...',
RequestType: 'get_mailaccounts',
RequestParams: []
})
};
soap.createClient(url, function(err, client) {
client.Api(args, function(err, result, rawResponse, soapHeader, rawRequest) {
console.log(util.inspect(result, {showHidden: false, depth: null}));
});
});
结果如下所示:
{
"return": {
"attributes": {
"xsi:type": "ns2:Map"
},
"item": [
{
"key": {
"$value": "Request",
"attributes": {
"xsi:type": "xsd:string"
}
},
"value": {
"attributes": {
"xsi:type": "ns2:Map"
},
"item": [
{
"key": {
"$value": "RequestTime",
"attributes": {
"xsi:type": "xsd:string"
}
},
"value": {
"$value": "1540823916",
"attributes": {
"xsi:type": "xsd:int"
}
}
},
{
"key": {
"$value": "RequestType",
"attributes": {
"xsi:type": "xsd:string"
}
},
"value": {
"$value": "get_mailaccounts",
"attributes": {
"xsi:type": "xsd:string"
}
}
},
{
"key": {
"$value": "RequestParams",
"attributes": {
"xsi:type": "xsd:string"
}
},
"value": {
"attributes": {
"SOAP-ENC:arrayType": "xsd:ur-type[0]",
"xsi:type": "SOAP-ENC:Array"
}
}
}
]
}
},
{
"key": {
"$value": "Response",
"attributes": {
"xsi:type": "xsd:string"
}
},
"value": {
"attributes": {
"xsi:type": "ns2:Map"
},
"item": [
{
"key": {
"$value": "FloodDelay",
"attributes": {
"xsi:type": "xsd:string"
}
},
"value": {
"$value": "0.5",
"attributes": {
"xsi:type": "xsd:float"
}
}
},
{
"key": {
"$value": "ReturnString",
"attributes": {
"xsi:type": "xsd:string"
}
},
"value": {
"$value": "TRUE",
"attributes": {
"xsi:type": "xsd:string"
}
}
},
{
"key": {
"$value": "ReturnInfo",
"attributes": {
"xsi:type": "xsd:string"
}
},
"value": {
"attributes": {
"SOAP-ENC:arrayType": "ns2:Map[1]",
"xsi:type": "SOAP-ENC:Array"
},
"item": {
"attributes": {
"xsi:type": "ns2:Map"
},
"item": [
{
"key": {
"$value": "mail_login",
"attributes": {
"xsi:type": "xsd:string"
}
},
"value": {
"$value": "xxxxxxx",
"attributes": {
"xsi:type": "xsd:string"
}
}
},
{
"key": {
"$value": "mail_password",
"attributes": {
"xsi:type": "xsd:string"
}
},
"value": {
"$value": "xxxxxxx",
"attributes": {
"xsi:type": "xsd:string"
}
}
},
{
"key": {
"$value": "mail_adresses",
"attributes": {
"xsi:type": "xsd:string"
}
},
"value": {
"$value": "xx@xx.de",
"attributes": {
"xsi:type": "xsd:string"
}
}
},
]
}
}
}
]
}
}
]
}
}
对象包含的信息是好的,也是我所期望的。但是为什么嵌套这么奇怪呢?我从上述 PHP 代码中得到的结果对象如下所示:
[
{
"KasFloodDelay": 0.5,
"ReturnString": "TRUE",
"ReturnInfo": [
{
"mail_login": "xxxxxxx",
"mail_password": "xxxxxxx",
"mail_adresses": "xxxxxxx",
...
}
]
}
]
这就是我要的。
解决方案
推荐阅读
- php - 将对象转换为数组并获取其值
- r - 在R中的每一行中提取次要等位基因计数
- powershell - 在 PowerShell 中共享路径后切断完整路径
- excel - 在字段之间插入空行或移动条目
- c++ - 节点 12 (v8) - 将弃用的代码转换为“可能”版本
- machine-learning - 深度神经网络 - 要调整的参数顺序
- wordpress - Safari 不加载图片
- javascript - 不使用 MailComposer 和 Nodemailer 发送 BBC 电子邮件
- apache - 找不到虚拟主机对象
- javascript - 使用 vanilla JS 将 rel="noopener noreferrer nofollow" 添加到所有外部链接的最佳方法