我收到编译错误:TS2339: Property 'json' does not exist on type 'Object'
尝试在复杂对象上映射 json 时Model.SearchResult.RootObject
发生在res.json()
以下服务中:
import { Injectable } from '@angular/core';
import {ResultPrice} from '../models/result-prices.model';
import { BaseService } from '../shared-components/base-service/base.service';
import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest } from '@angular/common/http';
import { Observable } from 'rxjs/Rx';
import * as Model from '../models/results.model';
import { HttpClient } from '@angular/common/http';
import 'rxjs/add/operator/map';
@Injectable()
export class SearchResultService {
private apiUrl = 'http://someurl/api/SearchResult/';
constructor(public http: HttpClient ) {
}
getSearchResultTable(hash: number): Observable<Model.SearchResult.RootObject> {
let tmp = this.http.get('http://someurl/api/SearchResult/123')
.map(res => {
return res.json().results.map(item => {
return new Model.SearchResult.RootObject();
});
});
return tmp;
}
}
是否Observable
包含json
属性?也许我错过了一些import
?