C# 用C语言中的嵌套列表反序列化JSON#

C# 用C语言中的嵌套列表反序列化JSON#,c#,json,nested,C#,Json,Nested,我正在用C#对一本词典进行序列化和反序列化。我的数据结构是: public class DataField { private string _Name; public string Name { get { return _Name; } set { _Name = value; } } private string _Label; public s

我正在用C#对一本词典进行序列化和反序列化。我的数据结构是:

    public class DataField
{
    private string _Name;
    public string Name
    {
        get { return _Name; }
        set
        {
            _Name = value;
        }
    }

    private string _Label;
    public string Label
    {
        get { return _Label; }
        set
        {
            _Label = value;
        }
    }

    private ControlType _TypeOfControl;
    public ControlType TypeOfControl
    {
        get { return _TypeOfControl; }
        set { _TypeOfControl = value; }
    }

    private int _Width;
    public int Width
    {
        get { return _Width; }
        set
        {
            _Width = value;
        }
    }
    private DataType _DataType;
    public DataType DataType
    {
        get { return _DataType; }
        set { _DataType = value; }
    }

    private Control _ControlAccessor;
    public Control ControlAccessor
    {
        get { return _ControlAccessor; }
        set { _ControlAccessor = value; }
    }


    private Type _ControlType;
    public Type ControlType
    {
        get { return _ControlType; }
        set { _ControlType = value; }
    }

    private List<KeyValuePair<string, string>> _Items;
    public List<KeyValuePair<string, string>> Items
    {
        get { if (_Items == null) _Items = new List<KeyValuePair<string, string>>(); return _Items; }
        set { _Items = value; }
    }
我得到的字符串是正确的:

{"Title" {"Name":"Title","Label":null,"TypeOfControl":0,"Width":200,"DataType":0,"ControlAccessor":null,"ControlType":null,"Items":[]}
,"Price":{"Name":"Price","Label":null,"TypeOfControl":0,"Width":100,"DataType":1,"ControlAccessor":null,"ControlType":null,"Items":[]}
,"Category":{"Name":"Category","Label":null,"TypeOfControl":0,"Width":100,"DataType":1,"ControlAccessor":null,"ControlType":null,"Items":[]}
,"Test":{"Name":"Test","Label":null,"TypeOfControl":0,"Width":100,"DataType":1,"ControlAccessor":null,"ControlType":null,"Items":[]}
,radioGeo":{"Name":"radioGeo","Label":null,"TypeOfControl":3,"Width":0,"DataType":0,"ControlAccessor":null,"ControlType":null
,"Items":[{"Key":"Position","Value":"posit"},{"Key":"Area","Value":"area"},{"Key":"Area","Value":"area"}]}
,"htmled":{"Name":"htmled","Label":null,"TypeOfControl":2,"Width":170,"DataType":0,"ControlAccessor":null,"ControlType":null,"Items":[]}}";
当我反序列化它时,几乎一切都是正确的。问题在于嵌套列表。虽然它们序列化得很好,但当我将其放回一起时,列表是空的


有什么建议吗?

我想您使用的是Json.net 我在工作中遇到了同样的问题,列表的反序列化是不完整的。此错误已添加到项目的问题跟踪程序中。我们发现的解决方法是不将列表作为对象中的最后一个变量


希望这能在等待修补程序时对您有所帮助。

刚刚尝试过这一方法,但没有解决问题。我正在使用System.Web.Script.Serialization;我切换到json.net并成功地尝试了上述建议!!
{"Title" {"Name":"Title","Label":null,"TypeOfControl":0,"Width":200,"DataType":0,"ControlAccessor":null,"ControlType":null,"Items":[]}
,"Price":{"Name":"Price","Label":null,"TypeOfControl":0,"Width":100,"DataType":1,"ControlAccessor":null,"ControlType":null,"Items":[]}
,"Category":{"Name":"Category","Label":null,"TypeOfControl":0,"Width":100,"DataType":1,"ControlAccessor":null,"ControlType":null,"Items":[]}
,"Test":{"Name":"Test","Label":null,"TypeOfControl":0,"Width":100,"DataType":1,"ControlAccessor":null,"ControlType":null,"Items":[]}
,radioGeo":{"Name":"radioGeo","Label":null,"TypeOfControl":3,"Width":0,"DataType":0,"ControlAccessor":null,"ControlType":null
,"Items":[{"Key":"Position","Value":"posit"},{"Key":"Area","Value":"area"},{"Key":"Area","Value":"area"}]}
,"htmled":{"Name":"htmled","Label":null,"TypeOfControl":2,"Width":170,"DataType":0,"ControlAccessor":null,"ControlType":null,"Items":[]}}";