我从服务器获取了一个xml响应,我需要获取
xml response (what is in the JSON 'response' below):
...<response><results><result><zpid>21853941</zpid></result></results>...</response>
var xml2js = require('xml2js');
var parser = new xml2js.Parser();
parser.parseString(body, function(err, result){
console.log(result);
console.log('----------------');
var x = result["SearchResults:searchresults"]["response"] //this works
//var x = result["SearchResults:searchresults"]["response"]["results"] //this doesn't
console.log(x);
x.forEach(function(e){ //this grabs object
console.log('e: ' +e)
});
});
所以这是输出:
OUTPUT:
result:
{ 'SearchResults:searchresults':
{ '$':
{ 'xsi:schemaLocation': 'http://www.zillow.com/static/xsd/SearchResults.xsd https://www.zillowstatic.com/vstatic/b20c067/static/xsd/SearchResults.xsd',
'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
'xmlns:SearchResults': 'http://www.zillow.com/static/xsd/SearchResults.xsd' },
request: [ [Object] ],
message: [ [Object] ],
response: [ [Object] ] } } // <-need to get what is in here
----------------
x:
[ { results: [ [Object] ] } ]
e: [object Object]
我需要掌握“响应”中的内容。