【发布时间】:2016-03-23 23:38:06
【问题描述】:
我对 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:00: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);
【问题讨论】:
-
只有 id 被序列化
-
rpc来自哪里? -
这是来自 Betfair 的提要,它是这样来的
-
对象不匹配 - 你有一个包装的 jsonrpc 对象你必须考虑。
标签: c# json serialization types json.net