[英]Generic task for get list of objects from api
我正在 blazor 中构建一些解决方案
await api.ExecProcGetList<SomeClassT>(
(list) =>
{
foreach (item in list)
{
Console.WriteLine(item.ID);
}
StateHasChanged();
},
(msg) =>
{
Console.WriteLine("error" + msg);
}
);
所以在这个 api 服务中我有
public Task ExecProcGetList<T>(Action<List<T>> callback, Action<string> callbackOnFailed = null)
{
return Task.Factory.StartNew(async (n)=>
{
string endpoint = "sp/t/" + this.dbName + "/" + this.schema + "/" + this.procName;
var response = await this.httpClient.PostAsJsonAsync(endpoint, this.parameters);
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
callback( await response.Content.ReadFromJsonAsync<List<T>>());
}
else
{
if (callbackOnFailed != null) callbackOnFailed(response.Content.ReadAsStringAsync().Result.ToString());
else Console.WriteLine(response.Content.ReadAsStringAsync().Result.ToString());
}
}, System.Threading.Tasks.TaskCreationOptions.LongRunning);
}
我看到该列表是从 api 中获取的,但是我得到了这个 SomeClassT 的项目列表,其中包含空值。
属性名称没问题,所以我猜这个 T 没有正确传递给这个任务?
我应该如何解决这个问题? 谢谢并恭祝安康
编辑
class SomeClassT
{
public int ID
public int IDSiec;
}
原始反应
[{"ID":11401174,"IDSiec":1380},{"ID":11411073,"IDSiec":300},{"ID":11401172,"IDSiec":1308}]
好的,谢谢大家的提示,但没有一个是正确的问题是我失踪了
{ get; set; }
在 class 字段中,这很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.