Json反序列化为动态

时间:2018-06-05 14:14:29

标签: c# json dynamic .net-core

我和一些丑陋的Json一起工作。我相信它是从XML转换的,因此Json属性并不像预期的那样。

<TABLE border=1>
<TR><TD>MachineName</TD><TD>Sensor_ID</TD><TD>Alias</TD><TD>TS</TD><TD>Val</TD></TR>
<TR><TD>Machine 1</TD><TD>	19421238-2af4-41a4-819b-06c3e05067e7</TD><TD>T1</TD><TD>0001-01-01T00:00:00</TD><TD>20</TD></TR>
<TR><TD>Machine 1</TD><TD>19421238-2af4-41a4-819b-06c3e05067e7</TD><TD>T1</TD><TD>0001-01-01T00:00:01</TD><TD>20</TD></TR>
<TR><TD>Machine 1</TD><TD>	19421238-2af4-41a4-819b-06c3e05067e7</TD><TD>T1</TD><TD>0001-01-01T00:00:02</TD><TD>	21</TD></TR>
<TR><TD>Machine 1</TD><TD>19421238-2af4-41a4-819b-06c3e05067e7</TD><TD>T1</TD><TD>0001-01-01T00:00:03	</TD><TD>21</TD></TR>
<TR><TD>Machine 1</TD><TD>19421238-2af4-41a4-819b-06c3e05067e7</TD><TD>T2</TD><TD>0001-01-01T00:00:00	</TD><TD>25</TD></TR>
<TR><TD>Machine 1</TD><TD>19421238-2af4-41a4-819b-06c3e05067e7</TD><TD>T2</TD><TD>0001-01-01T00:00:01	</TD><TD>25</TD></TR>
<TR><TD>Machine 1</TD><TD>19421238-2af4-41a4-819b-06c3e05067e7</TD><TD>T2</TD><TD>0001-01-01T00:00:02	</TD><TD>26</TD></TR>
<TR><TD>Machine 1</TD><TD>19421238-2af4-41a4-819b-06c3e05067e7</TD><TD> T2</TD><TD>0001-01-01T00:00:03</TD><TD>27</TD></TR>
</TABLE>

所以我做的第一件事就是将json转换为"response": { "EventType": "SomeEvent", "data": { "Markets": { "market": [{ "@name": "Derby Dash", "Players": { "Player": [{ "@name": "Joe Soap", "@value": "15", "@categoryId": "1", "@categoryDesc": "runner", "#text": "30" }, { "@name": "Jolene Soap", "@value": "15", "@categoryId": "1", "@categoryDesc": "runner", "#text": "31" },

dynamic

然后,我可以获取所有数据,直到该属性的前缀为var jsonObject = JsonConvert.DeserializeObject<dynamic>(json);

@

您还会注意到另一个以foreach (var market in jsonObject.response.data.Markerts) { var marketInfo = new Market { Players = new List<PlayerInfo>(), Name = market. // How on earth do i get this property ???? }; } 为前缀的属性。我也不知道该怎么做。

0 个答案:

没有答案