我有以下代码和 json:
public class Labels
{
public Labels()
{}
public Label[] Label {get;set;}
}
public class Label
{
public Label()
{ }
public string Name { get; set; }
public int TorrentsInLabel { get; set; }
}
//...
Labels o = JsonConvert.DeserializeObject<Labels>(json);
//...
{"label":
[
["seq1",1]
,["seq2",2]
]}
我希望这个数组 ["seq1","1"] 反序列化为 Label 对象。我错过了什么?一些属性?
当我运行时出现异常:预期类型为“test_JSONNET.Label”的 JsonArrayContract 得到“Newtonsoft.Json.Serialization.JsonObjectContract”。
发送
格格
最佳答案
JsonConvert怎么知道“seq1”对应name,“1”对应TorrentsInLabel?请查看 JsonObjectAttribute、JsonPropertyAttribute、JsonArrayAttribute
关于c# - JsonConvert.DeserializeObject 的 JSON.net 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1553795/