【发布时间】:2017-03-23 15:59:59
【问题描述】:
过去三天我一直在处理这个问题。我想将通过 HTTP 检索的 XML 转换为 JSON,以便我可以在 ionic 2 中显示它。这是我在提供程序中的代码。任何帮助将不胜感激。谢谢!
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
import * as xml2js from "xml2js";
@Injectable()
export class News {
constructor(public http: Http) { }
public getData() {
this
.http
.get('https://www.ug.edu.gh/news.xml')
.map(res => {
var cleanedString = res.toString().replace("\ufeff", "");
xml2js
.parseString(cleanedString, (error, result) => {
console.log(result);
return result;
});
})
.subscribe((data) => {
console.log(data)
}, (err) => {
console.log(err)
});
}
}
【问题讨论】: