Issue
I'm trying to get some data form my web service.
I got this code to retrieve the data (XML) and convert it to 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);
});
}
and I'm getting back and 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
but I cant loop trough that Array. I tried it with *ngfor and also in the code behind.
Any Ideas?
Solution
As Meadow mentions in the comments:
You can get your array of string like this :
var myArrayRes: Array<string> = result.ArrayOfString.string;
(And now, you can iterate on myArrayRes)
Answered By - Ruthran Suhendran
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.