Angular & Ionic 获取 ASP.NET Web 服务

Angular & Ionic get ASP.NET Webservice

我正在尝试从我的网络服务中获取一些数据。

我得到这段代码来检索数据 (XML) 并将其转换为 JSON:

constructor(private http: HttpClient) {
  this.get();
}

private d: any;
get() {
    const headers = new HttpHeaders();
    const url = 'http://.........asmx/GetData';
    // return this.http.post(url, options);
    return this.http.get(url, {responseType: 'text'} ).subscribe (
        data => {
            const myData = data;
            this.parse(data);
            // console.log(myData);
            // console.log(this.d);
        },
        error => console.error(error),
        () => {
        });
}

parse(xmlString) {
    const parser = new xml2js.Parser();
    parser.parseString(xmlString, (err, result) => {
        this.d = result;
        console.log(result);
    });
}

我回来了,ArrayOfString

{ArrayOfString: {…}}
ArrayOfString:
$: {xmlns:xsd: "http://www.w3.org/2001/XMLSchema", xmlns:xsi: "http://www.w3.org/2001/XMLSchema-instance", xmlns: "http://............asmx/"}
string: (26) ["517
↵  ", "563
↵  ", "564
↵  ", "561
↵  ", "546
↵  ", "518
↵  ", "521
↵  ", "527
↵  ", "49

↵  ", "19
↵  ", "20
↵  ", "5
↵  ", "17
↵  ", "50
↵  ", "52
↵  ", "544
↵  ", "545
↵  ", "528
↵  ", "24606
↵  ", "24595
↵  ", "1216
↵  ", "5634
↵  ", "1012
↵  ", "517", "546", "1"]
__proto__: Object
__proto__: Object

但我无法循环遍历该数组。我用 *ngfor 和后面的代码试过了。

有什么想法吗?

作为:

您可以像这样获取字符串数组:

var myArrayRes: Array<string> = result.ArrayOfString.string;

(现在,您可以迭代 myArrayRes)