안녕하세요. HTTP 요청을 http : //www.google.com/content/http://www.google.com/support/bin/answer.py?hl=ko&hl=ko this rss 피드에서 보내려고합니다. 나는 HTML 페이지에서 {{posts}}
를 사용하는 경우Ionic2 http 요청. XML을 json으로?
makeRequest() { this.http.get('http://www.gazetaexpress.com/rss/auto-tech/?xml=1') .subscribe(data => { this.posts = data; console.log("request funktioniert"); }, error => { console.log(JSON.stringify(error.json())); }); }
는 반환 :이 시도
Response with status: 200 OK for URL: http://m.gazetaexpress.com/mobile/rss/auto-tech/?xml=1
사용하여 {{포스트 | json}} 전체 HTML 페이지를 반환합니다. 나는 xml2js 라이브러리를 가져 D
편집
: 나는 사용하여 시도 :
this.http.get('http://www.gazetaexpress.com/rss/ballina/?xml=1').map(res => res.json())
을 대신 첫 번째 라인하지만 오류 반환 :
TypeError: error.json is not a function
이 좀 도와주세요 입력 내용을 ts 파일로 가져옵니다.
import * as xml2js from "xml2js"
그리고가 요청을 변경 :
makeRequest() {
this.http.get('http://www.gazetaexpress.com/rss/auto-tech/?xml=1').subscribe(data => {
this.posts = data;
xml2js.parseString(this.posts, function (err, result) {
console.log(result);
});
}, error => {
console.log(JSON.stringify(error.json()));
});
}
콘솔은 undefined를 반환 ...
편집 2
내가 문제를 핫픽스 좋아요. 방금 구멍 문자열을 가져 와서 노드 구조를 사용하여 조각으로 자르고 this.posts.replace(/\\t|\\n|\\r/gi, "");
을 사용하여 이스케이프 처리 된 문자를 제거합니다. 확실히이 문제에 대한 좋은 라이브러리가 있어야합니다. 코드가 꽤 나쁜 것입니다;). 나는이 코드를 나중에 간과 할 것이고, 이제는 작동하고 괜찮습니다. 더 나은 아이디어가 있으면 언제든지 알려주십시오. D