【发布时间】:2017-11-07 18:02:03
【问题描述】:
我有以下由网络服务返回的 JSON:
[{
"Author": {
"Title": "Luis Valencia"
},
"Editor": {
"Title": "Luis Valencia"
},
"Id": 1,
"ID": 1,
"Title": "Generic List Item 1",
"Modified": "2017-10-23T20:02:22Z",
"Created": "2017-10-23T20:02:22Z"
},
{
"Author": {
"Title": "Luis Valencia"
},
"Editor": {
"Title": "Luis Valencia"
},
"Id": 2,
"ID": 2,
"Title": "Generic List Item 2",
"Modified": "2017-11-07T17:52:34Z",
"Created": "2017-11-07T17:52:34Z"
}
]
使用此代码:
let items: IListItem[];
// tslint:disable-next-line:max-line-length
requester.get(
`${siteUrl}/_api/web/lists/getbytitle('${listName}')/items?$select=Title,Id,Modified,Created,Author/Title,Editor/Title&$expand=Author,Editor`,
SPHttpClient.configurations.v1,
{
headers: {
"Accept": "application/json;odata=nometadata",
"odata-version": ""
}
}
)
.then((response: SPHttpClientResponse): Promise<{ value: IListItem[] }> => {
return response.json()
})
.then((json: { value: IListItem[] }) => {
console.log(JSON.stringify(json.value));
return this._listItems = json.value;
});
break;
如何将 json.value 转换为 IListItem 数组?这将在 THEN 语句中完成,但不知道如何。
更新 1 列表项
export interface IListItem {
[key: string]: any;
id: string;
title: string;
modified: Date;
created: Date;
modifiedby: string;
createdby: string;
}
【问题讨论】:
标签: javascript json typescript