gpt4 book ai didi

c# - 如何使用 C# 从 Sharepoint 列表中选择由单个 JSON 响应组成的记录?

转载 作者:太空宇宙 更新时间:2023-11-03 14:56:53 25 4
gpt4 key购买 nike

我正在尝试从 SharePoint 列表中提取单个 JSON 响应记录。可以有多个记录,但我一次只需要从 SharePoint 列表中选择一个记录。目前,我正在获取所有数据,然后对其进行迭代,但这不是必需的。我正在使用 Newsoft Json 反序列化响应。

代码:

    HttpWebRequest endpointRequest =   (HttpWebRequest)HttpWebRequest.Create(url); endpointRequest.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["singlesionuserid"].ToString(), ConfigurationManager.AppSettings["ItservicesPassword"].ToString());
endpointRequest.Method = "GET";
endpointRequest.Accept = "application/json;odata=verbose";
HttpWebResponse endpointResponse = (HttpWebResponse)endpointRequest
.GetResponse();

Stream receiveStream = endpointResponse.GetResponseStream();
StreamReader readStream = new StreamReader
(receiveStream, Encoding.UTF8);
dynamic results = JsonConvert.DeserializeObject<dynamic>
(readStream.ReadToEnd());

foreach (var item in results.d.results)
{
Newtonsoft.Json.Linq.JObject inputJson = Newtonsoft.Json.Linq.JObject.FromObject(item.CreatedBy);

// Read Properties of the JObject
var properties = inputJson.Properties();

foreach (JProperty property in properties)
{

url = property.Value.ToString();
var successList = JsonConvert.DeserializeObject<CreateByURI>(url);

最佳答案

我们可以使用 CSOM API 获取单个列表项。

这里有一个演示供您引用。

using System;
using Microsoft.SharePoint.Client;

namespace Microsoft.SDK.SharePointFoundation.Samples
{
class List_getItemByIdExample
{
static void Main()
{
string siteUrl = "http://MyServer/sites/MySiteCollection";

ClientContext clientContext = new ClientContext(siteUrl);
Web site = clientContext.Web;
List targetList = site.Lists.GetByTitle("Announcements");

// Get the list item from the Announcements list whose Id is 4.
// Note that this is the ID of the item in the list, not a reference to its position.
ListItem targetListItem = targetList.GetItemById(4);

// Load only the title.
clientContext.Load(targetListItem,
item => item["Title"]);
clientContext.ExecuteQuery();

Console.WriteLine("Request succeeded. \n\n");
Console.WriteLine("Retrieved item is: {0}", targetListItem["Title"]);
}
}
}

更多关于 CSOM API 的信息供您引用。 SharePoint CSOM API

关于c# - 如何使用 C# 从 Sharepoint 列表中选择由单个 JSON 响应组成的记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48638528/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com