Anaular2打字稿对象类型转换

时间:2017-03-08 06:53:12

标签: json typescript angular2-routing

我试图从json中获取model object来自http response call

以下JSONhttp response的正文部分,

{

"dataType": "RWSupplier",
"partyName": "Lifecare Pharmaceuticals",
"partyShortName": null,
"partySecondaryName": null,
"partySecondaryShortName": null,
"sortingName": "Lifecare Pharma",
"mailingName": null,
"entityType": "SP",
"partyType": "OG",
"partySubType": null,
"extPartyId": null,
"comments": null,
"prGenderType": null,
"prBirthDate": null,
"prSalutation": null,
"statusCode": null,
"lastUpdateDate": "2017-03-06T04:30:00.000+0000",
"lastUpdateUser": "RwAdmin",
"tinNum": "33450701833",
"cstNum": "790052 dt. 4/4/2001",
"stNum": null,
"dlNum1": "5324/MIII/20B",
"dlNum2": "5205/MIII/21B",
"limitList": [ ],
"tagList": [ ],
"buId": "510",
"partyId": "SP001011001" }

我为以上JSON数据创建了界面,如下所示,

export interface SupplierBrief {
dataType: string;
partyId: string;
buId: string;
partyName: string;
statusCode: string;
comments: string; }

因为我不需要从休息电话中提供的所有属性。

因为我计划从缓存中省略不必要的属性,并通过删除这些属性来减少内存。为此,我把我的服务写成了打击。

return this.http.request(path, requestOptions).map((response: Response) => {
            return response.json() as models.SupplierBrief;
        });

SupplierBrief仍然包含休息调用返回的所有属性。

我可能会误解模型对象的概念,请指正。

1 个答案:

答案 0 :(得分:0)

不,你必须做这项工作。创建一个新对象,设置值,返回它。