I have the following JSON which is returned by a webservice:
[{
"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"
}
]
Using this code:
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;
How can convert the json.value to an Array of IListItem? that would be done in the THEN statement, but dont know how to.
Update 1 IListItem
export interface IListItem {
[key: string]: any;
id: string;
title: string;
modified: Date;
created: Date;
modifiedby: string;
createdby: string;
}