无法对json数组进行对象

发布于 2025-02-13 03:24:55 字数 1727 浏览 1 评论 0原文

    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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

橙味迷妹 2025-02-20 03:24:56

我注意到的第一件事是,您的结果类将尝试绑定到称为“数据”的属性,如JSON字符串所示,应称为“数据”。
Based on the json string I think you should try to deserialize to:

public partial class Result
{
    public ArastirmaRaporListesiResult ArastirmaRaporListesiResult { get; set; }
}

public partial class ArastirmaRaporListesiResult
{
    public Datum[] Data { get; set; }
    public long ErrorCode { get; set; }
    public object ErrorMessage { get; set; }
    public long StatusCode { get; set; }
}

public partial class Datum
{
    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 long RaporId { get; set; }
    public string RaporTarih { get; set; }
    public string Url { get; set; }
}

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:

public partial class Result
{
    public ArastirmaRaporListesiResult ArastirmaRaporListesiResult { get; set; }
}

public partial class ArastirmaRaporListesiResult
{
    public Datum[] Data { get; set; }
    public long ErrorCode { get; set; }
    public object ErrorMessage { get; set; }
    public long StatusCode { get; set; }
}

public partial class Datum
{
    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 long RaporId { get; set; }
    public string RaporTarih { get; set; }
    public string Url { get; set; }
}

For reference I used https://app.quicktype.io/ to generate the class

空名 2025-02-20 03:24:56
public class ArastirmaRaporListesiResult
{
    public List<Datum> Data { get; set; }
    public int ErrorCode { get; set; }
    public object ErrorMessage { get; set; }
    public int StatusCode { get; set; }
}
public class Datum
{
    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 int RaporId { get; set; }
    public string RaporTarih { get; set; }
    public string Url { get; set; }
}
public class Root
{
    public ArastirmaRaporListesiResult ArastirmaRaporListesiResult { get; set; }
}

root myDeserializedClass = jsonConvert.DeserializeObject(myjsonresponse);

它在这种状态下起作用。
谢谢。

public class ArastirmaRaporListesiResult
{
    public List<Datum> Data { get; set; }
    public int ErrorCode { get; set; }
    public object ErrorMessage { get; set; }
    public int StatusCode { get; set; }
}
public class Datum
{
    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 int RaporId { get; set; }
    public string RaporTarih { get; set; }
    public string Url { get; set; }
}
public class Root
{
    public ArastirmaRaporListesiResult ArastirmaRaporListesiResult { get; set; }
}

Root myDeserializedClass = JsonConvert.DeserializeObject(myJsonResponse);

It works in this state.
Thanks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文