映射 https 响应时获取 [object Object]
Getting [object Object] while mapping https response
我在 angular 10.
中使用 Observable 地图时得到一个 [object Object]
这是来自 API 服务的响应对象。
{
"result": {
"subject": {
"name": "ROBERT JAZGARA",
"nip": "7272445205",
"statusVat": "Czynny",
"regon": "472301670",
"pesel": null,
"krs": null,
"residenceAddress": "ZAGŁOBY 21/10, 02-495 WARSZAWA",
"workingAddress": null,
"representatives": [],
"authorizedClerks": [],
"partners": [],
"registrationLegalDate": "2002-05-21",
"registrationDenialBasis": null,
"registrationDenialDate": null,
"restorationBasis": null,
"restorationDate": null,
"removalBasis": null,
"removalDate": null,
"accountNumbers": [
"95213000042001029002150001",
"78105019241000009719369622"
],
"hasVirtualAccounts": false
},
"requestId": "mbn71-88a34h6",
"requestDateTime": "27-07-2020 23:52:30"
}
}
这是我创建的用于映射响应的模型。
export interface VatAPI {
result: EntityResponse;
}
export interface EntityResponse {
subjects: Entity[];
requestDateTime: string;
requestId: string;
}
export interface Entity {
authorizedClerks: EntityPerson[];
regon: string;
workingAddress: string;
hasVirtualAccounts: boolean;
statusVat: string;
krs: string;
restorationBasis: string;
accountNumbers: string[];
registrationDenialBasis: string;
representatives: EntityPerson[];
residenceAddress: string;
registrationDenialDate: Date;
restorationDate: Date;
name: string;
registrationLegalDate: Date;
removalBasis: string;
removalDate: Date;
nip: string;
partners: EntityPerson[];
pesel: string;
}
export interface EntityPerson {
firstName: string;
lastName: string;
nip: string;
companyName: string;
}
服务 class 调用 https 并映射响应。
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import {
HttpClientModule,
HttpClient,
HttpParams,
} from '@angular/common/http';
@Injectable()
export class ApiService {
constructor(private httpclient: HttpClient) {}
getcomments(): Observable<any> {
return this.httpclient.get(
'https://wl-api.mf.gov.pl/api/search/nip/7272445205?date=2020-07-27'
);
}
}
这是调用 api.service.ts
的 app.component.ts
import { Component } from '@angular/core';
import { VatAPI } from './classes/vatapi';
import { ApiService } from './services/api.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
constructor(private ApiService: ApiService) {}
lstresult: VatAPI;
// tslint:disable-next-line: use-lifecycle-interface
ngOnInit(): void {
this.ApiService.getcomments().subscribe((data) => {
this.lstresult = data;
});
}
}
我的app.comonent.html看起来像这样
<h2>Get Request (https://wl-test.mf.gov.pl:9091/wykaz-podatnikow/api/search/nip/7272445205?date=2020-07-27)</h2>
<span>{{ lstresult }}</span>
当我为项目提供服务时,我得到了 [object Object] 响应。哪里错了我想不通请帮忙
使用json管道查看数据。
<span>{{ lstresult | json }}</span>
我在 angular 10.
中使用 Observable 地图时得到一个 [object Object]这是来自 API 服务的响应对象。
{
"result": {
"subject": {
"name": "ROBERT JAZGARA",
"nip": "7272445205",
"statusVat": "Czynny",
"regon": "472301670",
"pesel": null,
"krs": null,
"residenceAddress": "ZAGŁOBY 21/10, 02-495 WARSZAWA",
"workingAddress": null,
"representatives": [],
"authorizedClerks": [],
"partners": [],
"registrationLegalDate": "2002-05-21",
"registrationDenialBasis": null,
"registrationDenialDate": null,
"restorationBasis": null,
"restorationDate": null,
"removalBasis": null,
"removalDate": null,
"accountNumbers": [
"95213000042001029002150001",
"78105019241000009719369622"
],
"hasVirtualAccounts": false
},
"requestId": "mbn71-88a34h6",
"requestDateTime": "27-07-2020 23:52:30"
}
}
这是我创建的用于映射响应的模型。
export interface VatAPI {
result: EntityResponse;
}
export interface EntityResponse {
subjects: Entity[];
requestDateTime: string;
requestId: string;
}
export interface Entity {
authorizedClerks: EntityPerson[];
regon: string;
workingAddress: string;
hasVirtualAccounts: boolean;
statusVat: string;
krs: string;
restorationBasis: string;
accountNumbers: string[];
registrationDenialBasis: string;
representatives: EntityPerson[];
residenceAddress: string;
registrationDenialDate: Date;
restorationDate: Date;
name: string;
registrationLegalDate: Date;
removalBasis: string;
removalDate: Date;
nip: string;
partners: EntityPerson[];
pesel: string;
}
export interface EntityPerson {
firstName: string;
lastName: string;
nip: string;
companyName: string;
}
服务 class 调用 https 并映射响应。
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import {
HttpClientModule,
HttpClient,
HttpParams,
} from '@angular/common/http';
@Injectable()
export class ApiService {
constructor(private httpclient: HttpClient) {}
getcomments(): Observable<any> {
return this.httpclient.get(
'https://wl-api.mf.gov.pl/api/search/nip/7272445205?date=2020-07-27'
);
}
}
这是调用 api.service.ts
的 app.component.tsimport { Component } from '@angular/core';
import { VatAPI } from './classes/vatapi';
import { ApiService } from './services/api.service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
constructor(private ApiService: ApiService) {}
lstresult: VatAPI;
// tslint:disable-next-line: use-lifecycle-interface
ngOnInit(): void {
this.ApiService.getcomments().subscribe((data) => {
this.lstresult = data;
});
}
}
我的app.comonent.html看起来像这样
<h2>Get Request (https://wl-test.mf.gov.pl:9091/wykaz-podatnikow/api/search/nip/7272445205?date=2020-07-27)</h2>
<span>{{ lstresult }}</span>
当我为项目提供服务时,我得到了 [object Object] 响应。哪里错了我想不通请帮忙
使用json管道查看数据。
<span>{{ lstresult | json }}</span>