gpt4 book ai didi

c# - 我如何在 C# 中解析 JSON 字符串获取错误无法反序列化当前 JSON 对象(例如 {“name” :“value” })

转载 作者:行者123 更新时间:2023-11-30 18:25:28 24 4
gpt4 key购买 nike

我尝试了以下代码,但无法解析 json 字符串。什么时候我正在解析我收到此错误:

Cannot deserialize the current JSON object (e.g. {“name”:“value”}) into type 'System.Collections.Generic.List`1

   HiddenField1.Value = "{\"AlertDataList\":[{\"header\":\"YTD Noresp 04/01/2010 - 01/31/2011 Created On 10/02/2013\",\"type\":\"High      \",\"NoResponse\":\"0\",\"NoResponsePct\":\"      0.00%\",\"Response\":\"1\",\"ResponsePct\":\"    100.00%\",\"All\":\"1\",\"accountperiodid\":\"11306\",\"navigateUrl\":\"windowpane://Insights.exe/HCI.Insights.Windows.Forms.Converted.FormFinalert…&responseType=NoResp&accountPeriodId=11306&alertType=High&hasResponses=All\",\"navigateResponsesUrl\":\"windowpane://Insights.exe/HCI.Insights.Windows.Forms.Converted.FormFinalert…responseType=NoResp&accountPeriodId=11306&alertType=High&hasResponses=Resp\",\"navigateNoResponsesUrl\":\"windowpane://Insights.exe/HCI.Insights.Windows.Forms.Converted.FormFinalert…D&responseType=NoResp&accountPeriodId=11306&alertType=High&hasResponses=No Resp\"},{\"header\":\"YTD Noresp 04/01/2010 - 01/31/2011 Created On 10/02/2013\",\"type\":\"Medium\",\"NoResponse\":\"0\",\"NoResponsePct\":\"      0.00%\",\"Response\":\"1\",\"ResponsePct\":\"    100.00%\",\"All\":\"1\",\"accountperiodid\":\"11306\",\"navigateUrl\":\"windowpane://Insights.exe/HCI.Insights.Windows.Forms.Converted.FormFinalert…esponseType=NoResp&accountPeriodId=11306&alertType=Medium&hasResponses=All\",\"navigateResponsesUrl\":\"windowpane://Insights.exe/HCI.Insights.Windows.Forms.Converted.FormFinalert…sponseType=NoResp&accountPeriodId=11306&alertType=Medium&hasResponses=Resp\",\"navigateNoResponsesUrl\":\"windowpane://Insights.exe/HCI.Insights.Windows.Forms.Converted.FormFinalert…responseType=NoResp&accountPeriodId=11306&alertType=Medium&hasResponses=No Resp\"},{\"header\":\"YTD Noresp 04/01/2010 - 01/31/2011 Created On 10/02/2013\",\"type\":\"All\",\"NoResponse\":\"0\",\"NoResponsePct\":\"      0.00%\",\"Response\":\"2\",\"ResponsePct\":\"    100.00%\",\"All\":\"2\",\"accountperiodid\":\"11306\",\"navigateUrl\":\"windowpane://Insights.exe/HCI.Insights.Windows.Forms.Converted.FormFinalert…D&responseType=NoResp&accountPeriodId=11306&alertType=All&hasResponses=All\",\"navigateResponsesUrl\":\"windowpane://Insights.exe/HCI.Insights.Windows.Forms.Converted.FormFinalert…&responseType=NoResp&accountPeriodId=11306&alertType=All&hasResponses=Resp\",\"navigateNoResponsesUrl\":\"windowpane://Insights.exe/HCI.Insights.Windows.Forms.Converted.FormFinalert…TD&responseType=NoResp&accountPeriodId=11306&alertType=All&hasResponses=No Resp\"}]}"


public void AlertTable()
{
List<alertMain> json = JsonConvert.DeserializeObject <List<alertMain>>((HiddenField1.Value).ToString());

}

public class alert
{
[JsonProperty("header")]
public string header { get; set; }

[JsonProperty("type")]
public string type { get; set; }

[JsonProperty("NoResponse")]
public string NoResponse { get; set; }

[JsonProperty("NoResponsePct")]
public string NoResponsePct { get; set; }

[JsonProperty("Response")]
public string Response { get; set; }

[JsonProperty("ResponsePct")]
public string ResponsePct { get; set; }

[JsonProperty("All")]
public string All { get; set; }

[JsonProperty("accountperiodid")]
public string accountperiodid { get; set; }

[JsonProperty("navigateUrl")]
public string navigateUrl { get; set; }

[JsonProperty("navigateResponsesUrl")]
public string navigateResponsesUrl { get; set; }

[JsonProperty("navigateNoResponsesUrl")]
public string navigateNoResponsesUrl { get; set; }
}

public class alertMain
{
[JsonProperty("AlertDataList")]
public List<alert> AlertDataList { get; set; }
}

最佳答案

尝试改变隐藏字段的值

HiddenField1.Value = "{\"AlertDataList\":[{...}]}"

HiddenField1.Value = "[{\"AlertDataList\":[{...}]}]"

关于c# - 我如何在 C# 中解析 JSON 字符串获取错误无法反序列化当前 JSON 对象(例如 {“name” :“value” }),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30095331/

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