使用Typescript获取XML

时间:2017-01-10 14:10:50

标签: json xml typescript cors

您好我是打字稿的新手。 我如何获得XML数据(CORS)。

import { Injectable, Component} from '@angular/core';
import { Headers, Http, Response, Jsonp } from '@angular/http';

import 'rxjs/add/operator/toPromise';

import { Weather } from '../models/weather';



@Injectable()
export class WeatherStationService{

    constructor(
        //private http: Http,
        private jsonp: Jsonp
    ){}
    private weatherStationUrl = 'http://meteo.physic.ut.ee/xml/data3.php';

    private handleError(error: any): Promise<any> {
        console.error('An error occurred', error);
        return Promise.reject(error.message || error);
    }

    getWeatherReports(): Promise<Weather[]> {
    return this.jsonp
      .get(this.weatherStationUrl)
      .toPromise()
      .then(response => response.json().data as Weather[])
      .catch(this.handleError);
    }


}

目前它将检索JSON,但我需要它作为XML,然后我需要将检索到的XML解析为JSON。 请帮忙:)!

0 个答案:

没有答案