JSON 无法正确序列化



我对JSON非常陌生,但试图让以下内容发挥作用,但只进行ID序列化,我怀疑我需要以某种方式更深地嵌套到字符串中:

字符串:

{"jsonrpc":"2.0","result":[{"event":{"id":"27727330","name":"Germany U21 v Faroe Islands U21","countryCode":"DE","timezone":"Europe/London","openDate":"2016-03-24T19:00:00.000Z"},"marketCount":24}],"id":1}

{"jsonrpc":"2.0","result":[{"event":{"id":"27727330","name":"Germany U21 v Faroe Islands U21","countryCode":"DE","timezone":"Europe/London","openDate":"2016-03-24T19:0:00.000Z"},"marketCount":24}],"id":1}

类别:

public class EventListing
    {
    [JsonProperty(PropertyName = "id")]
    public string id { get; set; }
    [JsonProperty(PropertyName = "name")]
    public string name { get; set; }
    [JsonProperty(PropertyName = "countryCode")]
    public string countryCode { get; set; }
    [JsonProperty(PropertyName = "timezone")]
    public string timezone { get; set; }
    [JsonProperty(PropertyName = "marketCount")]
    public string marketCount { get; set; }
    [JsonProperty(PropertyName = "openDate")]
    public DateTime? openDate { get; set; }
}

有问题的代码:

EventListing Test = Newtonsoft.Json.JsonConvert.DeserializeObject<EventListing>(theStringAbove);

修正了,我必须创建另一个类EventResult,它在深入JSON 之前收集顶级数据

    public class EventResult
    {
    [JsonProperty(PropertyName = "event")]
    public Event Event { get; set; }
    [JsonProperty(PropertyName = "marketCount")]
    public int MarketCount { get; set; }
    }

相关内容

  • 没有找到相关文章

最新更新