[英]ASP.NET C# Deserialized Json Object
I have json like this我有这样的 json
{
"reader_name":"FX9600EAF871",
"mac_address":"84:24:8D:FC:0E:AD",
"tag_reads":[
{
"epc":"E28068100000003C0A05E3B7",
"antennaPort":"1",
"peakRssi":"-31",
"seenCount":"2458",
"timeStamp":"14/02/2022 22:50:24:356",
"channelIndex":"5"
}
]
}
I try using this code我尝试使用这段代码
public class TagRead
{
public string epc { get; set; }
public string pc { get; set; }
public string antennaPort { get; set; }
public string peakRssi { get; set; }
public string seenCount { get; set; }
public string timeStamp { get; set; }
public string phase { get; set; }
public string channelIndex { get; set; }
public string isHeartBeat { get; set; }
}
public class Hdr
{
public string reader_name { get; set; }
public string mac_address { get; set; }
public List<TagRead> tag_reads { get; set; }
}
var deserialized = Newtonsoft.Json.JsonConvert.DeserializeObject<Hdr>(json);
When try to print reader name using当尝试使用打印读者姓名时
deserialized.reader_name反序列化.reader_name
it gets result FX9600EAF87它得到结果 FX9600EAF87
but when print但是当打印
deserialized.tag_reads反序列化.tag_reads
it get nothing?它一无所获?
my question is How to get epc & antennaport data?我的问题是如何获取 epc 和天线端口数据?
thank you谢谢你
Because deserialized.tag_reads
is a collection instead of base type or string, you might get the result that you didn't want to get.因为deserialized.tag_reads
是一个集合而不是基本类型或字符串,所以您可能会得到您不想得到的结果。
How to get epc & antennaport data?如何获取 epc 和天线端口数据?
you might try to use deserialized.tag_reads
with foreach
to iterator the collection then do your logic您可能会尝试将deserialized.tag_reads
与foreach
一起使用以迭代集合然后执行您的逻辑
var deserialized = Newtonsoft.Json.JsonConvert.DeserializeObject<Hdr>(json);
foreach(var item in deserialized.tag_reads){
//item.epc
//item.antennaPort
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.