输入json对象:
"root" :{
"Yylb": {
"Yylb_id": [1,2]
},
"Fj": [
{
"Fjxx":1
},
{
"Fjxx":2
}
]
}
Outpu xml格式:
<root>
<Yylb>
<Yylb_id>1</Yylb_id>
<Yylb_id>1</Yylb_id>
</Yylb>
<Fj>
<Fjxx>1</Fjxx>
</Fj>
<Fj>
<Fjxx>2</Fjxx>
</Fj>
</root>
答案 0 :(得分:0)
尝试使用此节点模块:https://www.npmjs.com/package/js2xmlparser。
示例:
var js2xmlparser = require("js2xmlparser");
var data = {
"firstName": "John",
"lastName": "Smith"
};
console.log(js2xmlparser("person", data));
> <?xml version="1.0" encoding="UTF-8"?>
> <person>
> <firstName>John</firstName>
> <lastName>Smith</lastName>
> </person>
答案 1 :(得分:0)
您可以使用xml-js
使用步骤:-
安装包:- //In service
public obtenerPersonas() {
const url = 'http://127.0.0.1:8000/api/v1.0/abogado/personas';
return this.http.get(url);
}
//in your-component.ts file
this.listar.obtenerPersonas().subscribe(res => {
this.dataSource = res;
console.log(res);
});
然后在此代码段中添加代码:-
npm install --save xml-js
有关更多详细信息,请访问:-xml-js