角度5,rxjs映射到json,类型“ object”上不存在“ json”

Aru*_*E S 1 json rxjs ionic-framework rxjs5 angular

尝试观看在线视频,然后出现,这是我的新手,其他解决方案也帮不了我。

在此处输入图片说明

import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import 'rxjs/add/operator/map';

/*
  Generated class for the WeatherProvider provider.

  See https://angular.io/guide/dependency-injection for more info on providers
  and Angular DI.
*/
@Injectable()
export class WeatherProvider {
  apikey='7d2dc7a226a78c14';
  url;

  constructor(public http: HttpClient) {
    console.log('Hello WeatherProvider Provider');
    this.url='http://api.wunderground.com/api/'+this.apikey+'/conditions/q'
  }

    getWeather(city,state){
      return this.http.get(this.url+'/'+state+'/'+city+'.json')
        .map(res => res.json() );      
    }
}
Run Code Online (Sandbox Code Playgroud)

mar*_*tin 5

如果您使用的是新的HttpClient,则不需要解析JSON,因为它会自动为您解码:

https://angular.io/guide/http#type-checking-the-response

HttpClient.get()方法将JSON服务器响应解析为匿名Object类型。它不知道该对象的形状是什么。

也是https://angular.io/guide/http#requesting-non-json-data