将多个API响应合并到一个JSON对象C#中
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将多个API响应合并到一个JSON对象C#中相关的知识,希望对你有一定的参考价值。
我因为分页而多次从C#应用程序调用Sharepoint REST API,并且一次不能返回更多5000条记录。我通过循环调用API
for (int i = 0; i < 10000; i = i + 5000)
{
SP_StrainCodes = "GetByTitle('S%20Codes')/items?$skiptoken=Paged=TRUE%26p_ID=" + i + "&$top=1";
core_URL = BaseURL_SP + SP_StrainCodes;
using (var client_sharePoint = new HttpClient(handler))
{
var response = client_sharePoint.GetAsync(core_URL).Result;
var responsedata = await response.Content.ReadAsStringAsync();
returnObj = JsonConvert.DeserializeObject<SharepointDTO.RootObject>(responsedata);
if (returnObj.d.Next == null)
continue;
}
}
return returnObj;
}
如何组合第一次调用的returnObj和第二次调用并返回为一个Object
答案
像这样的东西:
List<SharepointDTO.RootObject> results = new List<SharepointDTO.RootObject>();
for (int i = 0; i < 10000; i = i + 5000)
{
SP_StrainCodes = "GetByTitle('S%20Codes')/items?$skiptoken=Paged=TRUE%26p_ID=" + i + "&$top=1";
core_URL = BaseURL_SP + SP_StrainCodes;
using (var client_sharePoint = new HttpClient(handler))
{
var response = client_sharePoint.GetAsync(core_URL).Result;
var responsedata = await response.Content.ReadAsStringAsync();
returnObj = JsonConvert.DeserializeObject<SharepointDTO.RootObject>(responsedata);
if (returnObj.d.Next == null)
continue;
}
results.Add(returnObj);
}
return results;
以上是关于将多个API响应合并到一个JSON对象C#中的主要内容,如果未能解决你的问题,请参考以下文章