【发布时间】:2020-04-09 01:32:05
【问题描述】:
这是我传入的 JSON 数据包:
{
"schema":{
"rid":0,
"$esn":"eventhub1",
"properties":[
{
"name":"deviceId",
"type":"String"
},
{
"name":"product",
"type":"String"
},
{
"name":"data.Temperature",
"type":"Double"
},
{
"name":"data.Humidity",
"type":"Double"
},
{
"name":"Diagnostic-Id",
"type":"String"
}
]
},
"$ts":"2019-12-16T14:34:10.159Z",
"values":[
"xxxx",
"testProduct",
27.399,
15.247,
"xxxxxx"
]
}
如何对 $ts 字段进行反序列化?由于我不能使用属性名前面的 $ 字段,我应该选择哪种方式前进?
这是我要反序列化的模型:
public class Event
{
public Schema schema { get; set; }
public List<object> values { get; set; }
public int? schemaRid { get; set; }
//public DateTime $ts { get; set; }
}
【问题讨论】:
-
您使用的是 JSON.NET 吗?在这种情况下,请查看 JsonProperty 属性。
-
您可以尝试将 [JsonProperty("$esn")] 属性添加到 Schema 类中的相应属性。
标签: c# asp.net json jsonconvert