我调用了一个返回 XML 的 get API,我要转换为 JSON,但是 xml2js 在元素数组中返回 [Object] [Circular] 和 [Array]。如何查看元素数组中的内容?
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var convert = require('xml-js');
var request = new XMLHttpRequest();
request.open("GET", url, true, username, password);
request.withCredentials = true;
request.send();
request.onreadystatechange=(e)=>{
var obj = convert.xml2js(request.responseText);
console.log(obj);
这是输出:
{ declaration:
{ attributes: { version: '1.0', encoding: 'UTF-8', standalone: 'yes' } },
elements:
[ { type: 'element',
name: 'model-response-list',
attributes: [Object],
elements: [Array] } ] }