json映射问题c#

时间:2017-07-03 20:36:15

标签: c# .net json

无法创建一个类以取消此json c#的原因导致该数字导致问题,而映射任何帮助都表示赞赏 创建类本身就是问题

{//this is the class name
"1504076400": {
    "VenueKey": "the-gazebo",
    "IsShortBook": false,
    "IsSaturday": false,
    "Slots": [{
            "TS": 1504098000,
            "String": "08-30-2017 6:00 AM",
            "IsAvailable": false
        },
        {
            "TS": 1504099800,
            "String": "08-30-2017 6:30 AM",
            "IsAvailable": false
        }
    ]
},//these numbers are causing problem
"1504162800": {
    "VenueKey": "the-gazebo",
    "IsShortBook": false,
    "IsSaturday": false,
    "Slots": [{
            "TS": 1504184400,
            "String": "08-31-2017 6:00 AM",
            "IsAvailable": false
        },
        {
            "TS": 1504186200,
            "String": "08-31-2017 6:30 AM",
            "IsAvailable": false
        }
    ]
}
}

1 个答案:

答案 0 :(得分:0)

我没有看到反序列化和json都没有问题。模型classe可以看起来像:

class Venue
{
    public string VenueKey { get; set; }

    public bool IsShortBook { get; set; }

    public bool IsSaturday { get; set; }

    public Slot[] Slots { get; set; }
}

class Slot
{
    public string TS { get; set; }

    public string @String { get; set; }

    public bool ISAvailable { get; set; }
}

desalialization工作正常: JsonConvert.DeserializeObject<Dictionary<string, Venue>>(json);