如何将以下JSON字符串反序列化为c#
中的数据表{
"m_MaxCapacity":2147483647,
"Capacity":1888,
"m_StringValue":"<table border=3><tr><th>Master ID</th><th>Tag ID</th><th>Plant ID</th><th>Machine Name</th><th>Sap ID</th><th>Log</th></tr><tr><td>2296</td><td>567</td><td>567</td><td>hjhnh</td><td>567</td><td>17-09-2016 15:03:04</td></tr><tr><td>2297</td><td>55555</td><td>567</td><td>hjhnh</td><td>567</td><td>17-09-2016 15:04:27</td></tr><tr><td>2298</td><td>55555</td><td>567</td><td>hjhnh</td><td>0000</td><td>17-09-2016 15:04:53</td></tr><tr><td>2299</td><td>55555</td><td>567</td><td>hjhnh</td><td>0000</td><td>17-09-2016 15:05:11</td></tr><tr><td>2300</td><td>6678</td><td>6754</td><td>nnn</td><td>789</td><td>17-09-2016 15:20:51</td></tr><tr><td>2301</td><td>6678</td><td>6754</td><td>AF</td><td>789</td><td>17-09-2016 15:23:57</td></tr><tr><td>2302</td><td>6678</td><td>6754</td><td>ttttttt</td><td>789</td><td>17-09-2016 15:33:22</td></tr><tr><td>2303</td><td>6678</td><td>6754</td><td>ttttttt</td><td>789</td><td>17-09-2016 15:43:10</td></tr><tr><td>2304</td><td>6678</td><td>6754</td><td>ttttttt</td><td>789</td><td>17-09-2016 15:43:23</td></tr><tr><td>2305</td><td>6678</td><td>6754</td><td>ttttttt</td><td>789</td><td>17-09-2016 15:43:50</td></tr><tr><td>2306</td><td>6678</td><td>6754</td><td>lmno</td><td>789</td><td>17-09-2016 15:49:25</td></tr><tr><td>2307</td><td>6678</td><td>6754</td><td>ttttttt</td><td>789</td><td>22-09-2016 11:23:16</td></tr><tr><td>2308</td><td>6678</td><td>6754</td><td>ttttttt</td><td>789</td><td>22-09-2016 11:40:07</td></tr><tr><td>2309</td><td>6678</td><td>6754</td><td>ccccc</td><td>789</td><td>22-09-2016 11:40:18</td></tr><tr><td>2310</td><td>6678</td><td>6754</td><td>ttttttt</td><td>789</td><td>22-09-2016 11:45:53</td></tr><tr><td>2311</td><td>6678</td><td>6754</td><td>ttttttt</td><td>789</td><td>22-09-2016 12:00:48</td></tr><tr><td>2312</td><td>6678</td><td>6754</td><td>mmmmmmmmmm</td><td>789</td><td>22-09-2016 12:00:52</td></tr></table>",
"m_currentThread":0
}
欢迎任何想法。
答案 0 :(得分:0)
首先,您必须将包Deserialize
添加到项目中。接下来用对象创建类。您可以使用http://json2csharp.com/这是非常有用的工具。最后你必须 public class RootObject
{
public long m_MaxCapacity { get; set; }
public int Capacity { get; set; }
public string m_StringValue { get; set; }
public int m_currentThread { get; set; }
}
string json= {"m_MaxCapacity":2147483647,"Capacity":1888,"m_StringValue":"Master IDTag IDPlant IDMachine NameSap IDLog2296567567hjhnh56717-09-2016 15:03:04229755555567hjhnh56717-09-2016 15:04:27229855555567hjhnh000017-09-2016 15:04:53229955555567hjhnh000017-09-2016 15:05:11230066786754nnn78917-09-2016 15:20:51230166786754AF78917-09-2016 15:23:57230266786754ttttttt78917-09-2016 15:33:22230366786754ttttttt78917-09-2016 15:43:10230466786754ttttttt78917-09-2016 15:43:23230566786754ttttttt78917-09-2016 15:43:50230666786754lmno78917-09-2016 15:49:25230766786754ttttttt78922-09-2016 11:23:16230866786754ttttttt78922-09-2016 11:40:07230966786754ccccc78922-09-2016 11:40:18231066786754ttttttt78922-09-2016 11:45:53231166786754ttttttt78922-09-2016 12:00:48231266786754mmmmmmmmmm78922-09-2016 12:00:52","m_currentThread":0}
List<RootObject> list = new List<RootObject>();
list= JsonConvert.DeserializeObject<List<RootObject>>(json);
你的json。尝试使用此示例。
(spynner) spynner$ pip3 install spynner
Requirement already satisfied (use --upgrade to upgrade): spynner in /Users/spynner/Envs/spynner/lib/python3.4/site-packages/spynner-2.19-py3.4.egg
Collecting six (from spynner)
Using cached six-1.10.0-py2.py3-none-any.whl
Collecting beautifulsoup4 (from spynner)
Using cached beautifulsoup4-4.5.1-py3-none-any.whl
Collecting unittest2 (from spynner)
Using cached unittest2-1.1.0-py2.py3-none-any.whl
Collecting pyquery (from spynner)
Using cached pyquery-1.2.13.tar.gz
Collecting autopy (from spynner)
Using cached autopy-0.51.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/zl/dpw1svbx2qjbl549qvzq2r640000gn/T/pip-build-3rvrid_c/autopy/setup.py", line 50
print 'Updating __init__.py'
^
SyntaxError: Missing parentheses in call to 'print'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/zl/dpw1svbx2qjbl549qvzq2r640000gn/T/pip-build-3rvrid_c/autopy/
答案 1 :(得分:0)
您可以使用:http://json2csharp.com/
你上课了:
public class RootObject
{
public long m_MaxCapacity { get; set; }
public int Capacity { get; set; }
public string m_StringValue { get; set; }
public int m_currentThread { get; set; }
}
然后您可以将其添加到您的上下文中。