我使用this解决方案来反序列化我的JSON字符串。我尽量避免使用第三方库。
但是,我正在使用的JSON字符串的结构如下:
{"BatchId":"32","BatchPriority":"NORMAL","Entries":{"Entry":
[{"EntryId":"185","EntryPriority":"HIGH","Value":"0.0"},
{"EntryId":"172","EntryPriority":"LOW","Value":"122.0"}]
}}
我能够解除我的JSON,将BatchId
和BatchPriority
设置为Batch
对象(见下文)。但是,我无法从JSON设置“条目”数组,其值似乎是一个JSON字符串本身。
我如何构建我的对象,以便我能够解除排序并将“条目”数组设置为Batch
对象,只需我能够设置BatchId
的值和BatchPriority
属性?我知道public Array Entries { get; set; }
错了,但我不确定如何解决这个问题。
Batch
对象:
public class Batch
{
public int BatchId { get; set; }
public string BatchPriority { get; set; }
public Array Entries { get; set; } //wrong
}
Entry
对象:
public class Entry
{
public int EntryId { get; set; }
public string EntryPriority { get; set; }
public double Value { get; set; }
}
答案 0 :(得分:1)
您可以创建一个包含List<Entry>
public class Entries
{
public List<Entry> Entry { get; set; }
}
如果您查看Json2csharp,它会为您生成课程。
答案 1 :(得分:0)
您的属性public Array Entries { get; set; }
是一个名为条目的System.Array
,您需要一个名为Entry的数组或Entry类集合。
public class Batch
{
public int BatchId { get; set; }
public string BatchPriority { get; set; }
public Entry[] Entry { get; set; }
}