使用Javascript访问JSON解析的SOAP信封

时间:2015-09-15 15:25:10

标签: javascript json node.js soap

这是我的第一篇文章,我对这个奇妙的发展世界感到陌生,所以如果这是一个愚蠢的问题,我会提前道歉。

我正在使用Xml2js发送soap请求。然后我将响应解析为json。我的问题是深入肥皂信封。这就是响应的样子:

{ 'soap:Envelope': { '$': { 'xmlns:soap': 'http://schemas.xmlsoap.org/soap/envelope/' }, 'soap:Header': [ [Object] ], 'soap:Body': [ [Object] ] } }

这是一个扩展视图

{ 'soap:Envelope': 
 { '$': { 'xmlns:soap': 'http://schemas.xmlsoap.org/soap/envelope/' },
 'soap:Header': 
  [ { DWHeader: 
       [ { '$': { xmlns: 'Some Xmls' },
           SenderInfo: 
            [ { ApplicationID: [ 'Id' ],
                Credentials: [ { AuthToken: [ 'Authtoken' ] } ] } ],
           GlobalTimeoutMS: [ '123' ],
           TrackingID: [ '123' ],
           TraceResults: 
            [ { TraceResult: 
                 [ { IPAddress: [ '0.0.0.0' ],
                     Instance: [ '123' ],
                     Actor: [ '123' ],
                     Timestamp: [ '2015-08-08T15:45:40.844Z' ],
                     DetailedMessage: [ '123' ] } ] } ],
           TraceSettings: [ { '$': { Enabled: 'false' } } ] } ] } ],
 'soap:Body': 
  [ { GetCurrentLocationOfAllMobilesResponse: 
       [ { '$': { xmlns: 'Some xmls' },
           Tracks: 
            [ { Track: 
                 [ { Id: [ 'Id' ],
                     TimeStamp: [ '2015-09-14T21:09:47Z' ],
                     HardwareId: [ 'Some id' ],
                     MobileName: [ 'Truck' ],
                     Lat: [ 'Some Lat' ],
                     Lon: [ 'Some Lon' ],
                     Heading: [ '0' ],
                     Speed: [ '0' ],
                     GPSLock: [ 'true' ],
                     Old: [ 'false' ],
                     Ping: [ 'false' ],
                     Motion: [ 'false' ],
                     Speeding: [ 'false' ],
                     Ignition: [ 'false' ],
                     IgnitionStatus: [ 'Engine Off' ],
                     Street: [ 'Address' ],
                     City: [ 'Some City' ],
                     StateProvince: [ 'Some State' ],
                     PostalCode: [ 'Some Zip' ],
                     County: [ 'Some County' ],
                     Rssi: [ '32' ],
                     Sats: [ '11' ],
                     TimeZone: [ 'Some Timezone' ],
                     Sensor1: [ 'true' ],
                     Sensor2: [ 'false' ] }
                    ] } ] } ] } ] } }

我需要Track数组但是当我尝试向下钻取时,我遇到了问题:肥皂:信封'和肥皂:身体'。

这是我的第一个问题,如果我没有发布足够的信息,请告诉我,我会提供更多信息。

谢谢!

1 个答案:

答案 0 :(得分:1)

您是否尝试过使用括号表示法?

var tracksArray = response['soap:Envelope']['soap:Body'][0].GetCurrentLocationOfAllMobilesResponse[0].Tracks

有关括号表示法的更多信息,请参阅此答案:https://stackoverflow.com/a/4968448/4178531