gpt4 book ai didi

C# JsonConvert 错误

转载 作者:行者123 更新时间:2023-12-02 22:10:39 25 4
gpt4 key购买 nike

<分区>

我有这个 Json 返回:

[
{
"url": "http://xxx.xxx.xxx",
"code": 0,
"aplication":
{
"version":
[
{
"silent": true,
"checksum": "9aabad09b09459ac6c9e54f9ca4eb5c4",
"size": 1250619,
"force": true,
"apply_message": "",
"id": 116,
"id_aplication": 4,
"number": "1.0.5.0",
"news": "",
"automatic": true,
"installation": "Setup.exe"
}
],
"division_name": "DNT",
"app_name": "MyApplication",
"id": 4,
"id_master": 0
},
"message": "New Application Found"
}
]

使用本网站 http://json2csharp.com/ ,我生成这些类:

public class Version
{
public bool silent { get; set; }
public string checksum { get; set; }
public int size { get; set; }
public bool force { get; set; }
public string apply_message { get; set; }
public int id { get; set; }
public int id_aplication { get; set; }
public string number { get; set; }
public string news { get; set; }
public bool automatic { get; set; }
public string installation { get; set; }
}


public class Aplication
{
public List<Version> version { get; set; }
public string division_name { get; set; }
public string app_name { get; set; }
public int id { get; set; }
public int id_master { get; set; }
}

public class RootObject
{
public string url { get; set; }
public int code { get; set; }
public Aplication aplication { get; set; }
public string message { get; set; }
}

然后,在我的 C# 代码中,我这样写:

RootObject test = JsonConvert.DeserializeObject<RootObject>(jsonResult);

但是,我收到这个错误:

Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[ConsoleAPP.Aplication]' 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 'aplication.version', line 1, position 227.

我阅读了一些关于此的提示,但对我没有帮助。例如:

Unable to parse JSON array in WCF REST

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