【问题标题】:Sharepoint List data formatSharepoint 列表数据格式
【发布时间】:2014-01-09 15:45:14
【问题描述】:

我正在使用 rest api 成功获取存储在 sharepoint 2013 中的列表。在客户端,我想遍历对象。谁能告诉我数据的结构。

【问题讨论】:

    标签: sharepoint sharepoint-list


    【解决方案1】:

    按如下方式遍历每个列表项:

     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/

    【讨论】:

    • 是的,我在某个时候得到了它。谢谢。我还想补充一点,我的字段名称是“DisplayName”,它没有出现在 data.d.results[index].DisplayName 中。将其更改为 ReportsName 就可以了。我不知道为什么它不起作用。
    【解决方案2】:

    它可以是 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();
    

    【讨论】:

    • 我能够收到 json。我想知道遍历每个列表项的 JSON 结构。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-15
    • 1970-01-01
    • 2017-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多