0

我收到编译错误: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

4

1 回答 1

0

你可以尝试给 map 的第一个参数res一个类型。像这样->

return this.http.get('http://someurl/api/SearchResult/123')
  .map(res: any) => {
    return res.json().results.map(item => {
      return new Model.SearchResult.RootObject();
    });
  });
于 2019-03-24T06:16:44.137 回答