Angular 角度类型脚本到Http JSON映射
要使用什么模式将结果从API映射到Typescript类(如装饰器等),不希望创建精确的副本Typescript类/JSON对象来匹配后端java对象 打字稿Angular 角度类型脚本到Http JSON映射,angular,typescript,angular-http,Angular,Typescript,Angular Http,要使用什么模式将结果从API映射到Typescript类(如装饰器等),不希望创建精确的副本Typescript类/JSON对象来匹配后端java对象 打字稿 export interface ISearchResult { Id: string; name: string; startDate?: Moment; endDate?: Moment; status?: string; count?: number; offeringCount?: number; }
export interface ISearchResult {
Id: string;
name: string;
startDate?: Moment;
endDate?: Moment;
status?: string;
count?: number;
offeringCount?: number;
}
export class SearchResult implements ISearchResult {
Id: string;
name: string;
startDate?: Moment;
endDate?: Moment;
status?: string;
count?: number;
offeringCount?: number;
}
API的结果如下所示。基本上,这不是一对一的映射
有没有一种方法可以在我的TypeScript中添加一些注释来映射到下面的对象
[
{
"product": [
{
"productPolicy": {},
"productDetails": [
{
"id": "30016719",
"statusIndicator": true,
"productExists": false,
"productName": "ABC",
"address": {
"city": "Denver",
"stateCode": "CO"
},
"payIndicator": false,
"productDelted": false,
"membershipGroupingSalesData": {},
"statusCode": "A
}
]
}
],
您的TS接口和API不匹配?您的TS接口和API不匹配?