gpt4 book ai didi

c# - RestSharp JSON 数组反序列化

转载 作者:可可西里 更新时间:2023-11-01 08:56:30 29 4
gpt4 key购买 nike

我以 JSON 格式启动此 RestSharp 查询:

var response = restClient.Execute<Report>(request);

我得到的响应包含这些数据

[
{
"Columns":
[
{"Name":"CameraGuid","Type":"Guid"},
{"Name":"ArchiveSourceGuid","Type":"Guid"},
{"Name":"StartTime","Type":"DateTime"},
{"Name":"EndTime","Type":"DateTime"},
{"Name":"TimeZone","Type":"String"},
{"Name":"Capabilities","Type":"UInt32"}
],
"Rows":
[
[
"00000001-0000-babe-0000-00408c71be50",
"3782fe37-6748-4d36-b258-49ed6a79cd6d",
"2013-11-27T17:52:00Z",
"2013-11-27T18:20:55.063Z",
"Eastern Standard Time",
2147483647
]
]
}
]

我正在尝试将其反序列化为这组类:

public class Report
{
public List<ReportResult> Results { get; set; }
}

public class ReportResult
{
public List<ColumnField> Columns { get; set; }
public List<RowResult> Rows { get; set; }
}

public class ColumnField
{
public string Name { get; set; }
public string Type { get; set; }
}

public class RowResult
{
public List<string> Elements { get; set; }
}

不幸的是,结果数据为空,我得到了这个异常:

Unable to cast object of type 'RestSharp.JsonArray' to type 'System.Collections.Generic.IDictionary`2[System.String,System.Object]'.

我不知道这里出了什么问题。我将不胜感激。

最佳答案

试试这个:

var response = restClient.Execute<List<ReportResult>>(request);

编辑

您还应该将 ReportResult 更改为:

public class ReportResult
{
public List<ColumnField> Columns { get; set; }
public List<List<string>> Rows { get; set; }
}

您可以去掉 ReportRowResult

关于c# - RestSharp JSON 数组反序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20251020/

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