Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 反序列化JSON,其中值是JSON字符串_C#_Json_Deserialization_Json Deserialization - Fatal编程技术网

C# 反序列化JSON,其中值是JSON字符串

C# 反序列化JSON,其中值是JSON字符串,c#,json,deserialization,json-deserialization,C#,Json,Deserialization,Json Deserialization,我使用这个解决方案来反序列化我的JSON字符串。如果可能的话,我会尽量避免使用第三方库 但是,我使用的JSON字符串的结构如下: {"BatchId":"32","BatchPriority":"NORMAL","Entries":{"Entry": [{"EntryId":"185","EntryPriority":"HIGH","Value":"0.0"}, {"EntryId":"172","EntryPriority":"LOW","Value":"122.0"}] }

我使用这个解决方案来反序列化我的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
属性的值?
我知道
公共数组条目{get;set;}
是错误的,但我不确定如何处理


批处理
对象:

public class Batch
{
    public int BatchId { get; set; }

    public string BatchPriority { get; set; }

    public Array Entries { get; set; } //wrong
}
public class Entry
{
    public int EntryId { get; set; }

    public string EntryPriority { get; set; }

    public double Value { get; set; }
}
条目
对象:

public class Batch
{
    public int BatchId { get; set; }

    public string BatchPriority { get; set; }

    public Array Entries { get; set; } //wrong
}
public class Entry
{
    public int EntryId { get; set; }

    public string EntryPriority { get; set; }

    public double Value { get; set; }
}

您可以创建一个包含
列表的类

公共类条目
{
公共列表项{get;set;}
}

如果您查看,它将为您生成类。

您的属性
公共数组条目{get;set;}
是一个
系统。数组
称为条目,您需要一个名为Entry的条目类数组或集合,例如

public class Batch
{
    public int BatchId { get; set; }

    public string BatchPriority { get; set; }

    public Entry[] Entry { get; set; } 
}