从SOAP响应中返回非唯一值

时间:2012-09-13 13:29:15

标签: html eclipse soap ibm-mobilefirst

所以我正在构建一个移动应用程序(使用IBM Worklight),它通过SOAP调用消耗一些Web服务。我能够使4个Web服务中的3个工作,拉回值等。该应用程序以HTML格式显示SOAP响应中的值。这基本上是从SOAP响应中提取值并显示的方式:

var submit = result.invocationResult.Envelope.Body.FinSummary.out.SubServices.ServiceName;

只要我想要显示的值是唯一的,这就可以正常工作。最终Web服务的SOAP响应非常长并且包含重复值。例如,SOAP响应如下所示:

<Envelope>
  <Header/>
    <Body>
      <FinSummary>
        <out>
          <SubServices>
            <....>
            <ServiceName>STRING</ServiceName>
            <....>
          </SubServices>
          <SubServices>
            <....>
            <ServiceName>STRING</ServiceName>
            <....>
          </SubServices>
              <SubServices>
            <....>
            <ServiceName>STRING</ServiceName>
            <....>
          </SubServices>
        </out>
      </FinSummary>
    </Body>
</Envelope>

我需要提取每个STRING,但SubServices / ServiceName节点显然不是唯一的。任何人都知道如何提取这些价值观?

2 个答案:

答案 0 :(得分:0)

result.invocationResult.Envelope.Body.FinSummary.out.SubServices应该被解析为数组,因此以下内容应该有效:

var serviceNames = [];
var subServices = result.invocationResult.Envelope.Body.FinSummary.out.SubServices;
for (var i=0;i<subServices.length; i++){
    serviceNames.push(subServices[i].ServiceName);
}

答案 1 :(得分:0)

为什么不使用会将JSON返回给应用程序的HTTP SOAP适配器?