如何解析json与对象和列表相同的属性? C#

时间:2018-01-31 09:45:12

标签: json parsing

在尝试解析JSON时,我收到有关类型的错误。我有这段代码:

public class Event
{

    [JsonProperty("eventKey")]
    public int EventKey { get; set; }

    [JsonProperty("displayOrder")]
    public int DisplayOrder { get; set; }

    [JsonProperty("subTypeKey")]
    public int SubTypeKey { get; set; }

    [JsonProperty("eventName")]
    public string EventName { get; set; }

    [JsonProperty("eventNameTranslated")]
    public string EventNameTranslated { get; set; }

    [JsonProperty("eventStatus")]
    public string EventStatus { get; set; }

    [JsonProperty("eventSort")]
    public string EventSort { get; set; }

    [JsonProperty("eventDateTime")]
    public DateTime EventDateTime { get; set; }

    [JsonProperty("classSortCode")]
    public string ClassSortCode { get; set; }

    [JsonProperty("typeFlagCode")]
    public string TypeFlagCode { get; set; }
}

public class Events
{

    [JsonProperty("num")]
    public int Num { get; set; }

    [JsonProperty("event")]
    public IList<Event> Event { get; set; }
}

public class Subtype
{

    [JsonProperty("subTypeKey")]
    public int SubTypeKey { get; set; }

    [JsonProperty("subTypeName")]
    public string SubTypeName { get; set; }

    [JsonProperty("displayOrder")]
    public int DisplayOrder { get; set; }

    [JsonProperty("events")]
    public Events Events { get; set; }
}

public class Subtypes
{

    [JsonProperty("num")]
    public int Num { get; set; }

    [JsonProperty("subtype")]
    public Subtype Subtype { get; set; }
}

但是我收到错误,因为它无法解析它,因为它有时会将类型作为List,有时也会作为对象。查看屏幕截图(子类型和事件)。 如何更改代码以支持不同类型?

json file

你能帮我解决这个问题吗?或者我需要阅读什么来解决我的问题?

0 个答案:

没有答案