无法对json数组进行对象
string res = "{\"ArastirmaRaporListesiResult\":{\"Data\":[{\"Baslik\":\"Akbank\",\"DosyaAd\":\"66245_AKBNK_27062022_OtomatikBUlten.pdf\",\"EnstrumanKod\":\"AKBNK\",\"KategoriAd\":\"Şirket Notu\",\"KategoriKod\":\"SIRKETRAPOR\",\"RaporId\":27573,\"RaporTarih\":\"27.06.2022\",\"Url\":\"http:\"},{\"Baslik\":\"Bim Mağazalar\",\"DosyaAd\":\"66243_BIMAS_27062022_OtomatikBUlten.pdf\",\"EnstrumanKod\":\"BIMAS\",\"KategoriAd\":\"Şirket Notu\",\"KategoriKod\":\"SIRKETRAPOR\",\"RaporId\":27571,\"RaporTarih\":\"27.06.2022\",\"Url\":\"http:\"}],\"ErrorCode\":0,\"ErrorMessage\":null,\"StatusCode\":200}}";
public class Result
{
public List<Data> Datas { get; set; }
public int ErrorCode { get; set; }
public string ErrorMessage { get; set; }
public int StatusCode { get; set; }
}
public class Data
{
public string Baslik { get; set; }
public string DosyaAd { get; set; }
public string EnstrumanKod { get; set; }
public string KategoriAd { get; set; }
public string KategoriKod { get; set; }
public string RaporId { get; set; }
public string RaporTarih { get; set; }
public string Url { get; set; }
}
var arastirmaContracts = JsonConvert.DeserializeObject<List< Result>>(res);
无法对当前的json对象(例如{“ name”:“ value”})type'system.collections.generic.generic.list'1 [finnet.program.program+arastirmaraporlistesiresults]' [1,2,3])要正确阐明。 要解决此错误要么将JSON更改为JSON阵列(例如[1,2,3])或更改供应类型,因此它是正常的.NET类型(例如,不是像Integer这样的原始类型,而不是类型的集合类型可以从JSON对象进行值得序列化的数组或列表。 JonobjectAttribute也可以将其添加到类型中,以强迫其从JSON对象进行验证。 路径“ Arastirmaraporlistesiresult”,第1行,位置31。
string res = "{\"ArastirmaRaporListesiResult\":{\"Data\":[{\"Baslik\":\"Akbank\",\"DosyaAd\":\"66245_AKBNK_27062022_OtomatikBUlten.pdf\",\"EnstrumanKod\":\"AKBNK\",\"KategoriAd\":\"Şirket Notu\",\"KategoriKod\":\"SIRKETRAPOR\",\"RaporId\":27573,\"RaporTarih\":\"27.06.2022\",\"Url\":\"http:\"},{\"Baslik\":\"Bim Mağazalar\",\"DosyaAd\":\"66243_BIMAS_27062022_OtomatikBUlten.pdf\",\"EnstrumanKod\":\"BIMAS\",\"KategoriAd\":\"Şirket Notu\",\"KategoriKod\":\"SIRKETRAPOR\",\"RaporId\":27571,\"RaporTarih\":\"27.06.2022\",\"Url\":\"http:\"}],\"ErrorCode\":0,\"ErrorMessage\":null,\"StatusCode\":200}}";
public class Result
{
public List<Data> Datas { get; set; }
public int ErrorCode { get; set; }
public string ErrorMessage { get; set; }
public int StatusCode { get; set; }
}
public class Data
{
public string Baslik { get; set; }
public string DosyaAd { get; set; }
public string EnstrumanKod { get; set; }
public string KategoriAd { get; set; }
public string KategoriKod { get; set; }
public string RaporId { get; set; }
public string RaporTarih { get; set; }
public string Url { get; set; }
}
var arastirmaContracts = JsonConvert.DeserializeObject<List< Result>>(res);
Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[Finnet.Program+ArastirmaRaporListesiResults]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'ArastirmaRaporListesiResult', line 1, position 31.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我注意到的第一件事是,您的结果类将尝试绑定到称为“数据”的属性,如JSON字符串所示,应称为“数据”。
Based on the json string I think you should try to deserialize to:
For reference I used https://app.quicktype.io /生成课程
The first thing i noticed is that your Result class will be trying to bind to a property called "Datas" where as the json string suggests it should be called "Data".
Based on the json string I think you should try to deserialize to:
For reference I used https://app.quicktype.io/ to generate the class
root myDeserializedClass = jsonConvert.DeserializeObject(myjsonresponse);
它在这种状态下起作用。
谢谢。
Root myDeserializedClass = JsonConvert.DeserializeObject(myJsonResponse);
It works in this state.
Thanks.