【发布时间】:2021-02-11 20:01:44
【问题描述】:
我正在从 API 接收此字符串 Json 格式。
string rawJson = "[{\"RequestID\":12345,\"Status\":100,\"ResponseMessage\": \"API Call Successful\",\"ResponseData\":[{\"EmployeeID\":\"1824\",\"MatchedDateTime\":[\"20 Oct 2020 06:41:45 AM\"]},{\"EmployeeID\":\"1214\",\"MatchedDateTime\":[\"20 Oct 2020 06:05:03 AM\"]}]}]"
我想要列表中的 ReponseData,所以我做了以下操作。
public class TO_JsonLogs
{
[Newtonsoft.Json.JsonProperty("ResponseData")]
public Dictionary<string, TO_JsonPunches> TO_JsonPunch { get; set; }
}
public class TO_JsonPunches
{
public string EmployeeID { get; set; }
public string MatchedDateTime { get; set; }
}
var logsJson = JsonConvert.DeserializeObject<TO_JsonLogs>(rawJson);
它在这一行给出以下错误。
将值
"[{"RequestID":12345,"Status":100,"ResponseMessage": "API Call Successful","ResponseData":[{"EmployeeID":"1824","MatchedDateTime":["20 Oct 2020 06:41:45 AM"]},{"EmployeeID":"1214","MatchedDateTime":["20 Oct 2020 06:05:03 AM"]}]}]"转换为类型“TO_JsonLogs”时出错。路径 '',第 1 行,位置 256。
知道如何在列表中获取这些数据。
【问题讨论】:
-
也许这可以帮助查看问题所在:newtonsoft.com/json/help/html/SerializationTracing.htm 另外,当我将此 json 放入 json2csharp 以创建模型时,它显示了一个列表
MatchedDateTime。 json2csharp.com
标签: c# asp.net json asp.net-mvc asp.net-mvc-4