【发布时间】:2014-01-09 15:45:14
【问题描述】:
我正在使用 rest api 成功获取存储在 sharepoint 2013 中的列表。在客户端,我想遍历对象。谁能告诉我数据的结构。
【问题讨论】:
标签: sharepoint sharepoint-list
我正在使用 rest api 成功获取存储在 sharepoint 2013 中的列表。在客户端,我想遍历对象。谁能告诉我数据的结构。
【问题讨论】:
标签: sharepoint sharepoint-list
按如下方式遍历每个列表项:
function (data)
{
if (data.d != undefined)
{
//Check if the list has data
if (data.d.results.length > 0)
{
//Iterate through each items fetched from the list
$.each(data.d.results, function(index, item)
{
var fieldVal= item.fieldName;
});
}
}
}
您可以使用以下网址在浏览器中查看列表的响应格式:
网站网址 + /_api/web/lists/getbytitle('listname')/items
更多信息请参考以下网址: http://sergeluca.wordpress.com/2013/01/20/sharepoint-2013-rest-odata-part-1-readingfetching-information-no-code/
【讨论】:
它可以是 XML 或 JSON。
见
http://msdn.microsoft.com/en-us/library/office/jj164022.aspx
以下代码演示了如果您是 使用跨域库并希望接收 OData 将列表表示为 XML 而不是 JSON。请参阅如何:访问 来自使用跨域库的应用程序的 SharePoint 2013 数据以获取更多信息 有关使用跨域库的信息。
HttpWebRequest endpointRequest = (HttpWebRequest)HttpWebRequest.Create(sharepointUrl.ToString() + "/_api/web/lists");
endpointRequest.Method = "GET";
endpointRequest.Accept = "application/json;odata=verbose";
endpointRequest.Headers.Add("Authorization", "Bearer " + accessToken);
HttpWebResponse endpointResponse = (HttpWebResponse)endpointRequest.GetResponse();
【讨论】: