Tommy

Tommy

  • NA
  • 134
  • 26.2k

Please, help to deserialize my JSON file on C#

Jul 11 2016 6:47 PM
&nbsp;<p align="left" style="font-size: 12pt;"> Hey smart people,</p><p style="font-size: 12pt;">Hope you are all well.&nbsp;Please,&nbsp;can someone help me with my C# and json code, I'll&nbsp;be super grateful.</p><div style="font-size: 12pt;">&nbsp;</div><div style="font-size: 12pt;">Here's the content of my&nbsp;<strong>mydata.json</strong> file which has to be loaded from URL</div><div style="font-size: 12pt;">&nbsp;</div><div style="font-size: 12pt;"><pre style='color: #000000; font-family: "Courier New"; font-size: 9pt; background-color: #ffffff;'><pre style='color: #000000; font-family: "Courier New"; font-size: 9pt; background-color: #ffffff;'>global.data.retrieve(<br />{<br /><span style="color: #008000; font-weight: bold;">"Status"</span>: <span style="color: #008000; font-weight: bold;">"SUCCESS"</span>,<br /><span style="color: #008000; font-weight: bold;">"total"</span>: <span style="color: #0000ff;">3</span>,<br /><span style="color: #008000; font-weight: bold;">"results"</span>:<br />{<br /><span style="color: #008000; font-weight: bold;">"Platform"</span>: [<br />{<br /><span style="color: #008000; font-weight: bold;">"type"</span>: <span style="color: #008000; font-weight: bold;">"AA"</span>,<br /><span style="color: #008000; font-weight: bold;">"Id"</span>: <span style="color: #008000; font-weight: bold;">"420"</span>,<br /><span style="color: #008000; font-weight: bold;">"service"</span>: <span style="color: #000080; font-weight: bold;">false</span>,<br /><span style="color: #008000; font-weight: bold;">"description"</span>: <span style="color: #008000; font-weight: bold;">""</span>,<br /><span style="color: #008000; font-weight: bold;">"imageUrl"</span>: <span style="color: #008000; font-weight: bold;">"http://www.somelink.com/file.jpg"</span>,<br /><span style="color: #008000; font-weight: bold;">"date"</span>: <span style="color: #008000; font-weight: bold;">"1457608735000"<br /></span>},<br />{<br /><span style="color: #008000; font-weight: bold;">"type"</span>: <span style="color: #008000; font-weight: bold;">"BB"</span>,<br /><span style="color: #008000; font-weight: bold;">"Id"</span>: <span style="color: #008000; font-weight: bold;">"307"</span>,<br /><span style="color: #008000; font-weight: bold;">"service"</span>: <span style="color: #000080; font-weight: bold;">false</span>,<br /><span style="color: #008000; font-weight: bold;">"description"</span>: <span style="color: #008000; font-weight: bold;">""</span>,<br /><span style="color: #008000; font-weight: bold;">"imageUrl"</span>: <span style="color: #008000; font-weight: bold;">"http://www.somelink.com/file.jpg"</span>,<br /><span style="color: #008000; font-weight: bold;">"date"</span>: <span style="color: #008000; font-weight: bold;">"1457608782000"<br /></span>},<br />{<br /><strong><span style="color: #008000;">"type"</span>: <span style="color: #008000;">"CC"</span>,<br /><span style="color: #008000;">"Id"</span>: <span style="color: #008000;">"114"</span>,<br /><span style="color: #008000;">"service"</span>: <span style="color: #000080;">true</span>,<br /><span style="color: #008000;">"description"</span>: <span style="color: #008000;">""</span>,<br /><span style="color: #008000;">"imageUrl"</span>: <span style="color: #008000;">"http://www.somelink.com/file.jpg"</span>,<br /><span style="color: #008000;">"date"</span>: </strong><span style="color: #008000;"><strong>"1457611015000"</strong><br /></span>}]<br />}<br />})</pre></pre>I've learnt a little about json, got to know what arrays and objects are but still stuck with my C#&nbsp;app.</div><div style="font-size: 12pt;">Please guys, I need slight help with my code. I'm really stuck with it&nbsp;: (</div><div style="font-size: 12pt;">&nbsp;</div><div style="font-size: 12pt;">On the click of the button I am looking to retrieve json data from the above file, which will be on the external web address: http://www.mydomain.com/mydata.json</div><div style="font-size: 12pt;">&nbsp;</div><div style="font-size: 12pt;">By the way, I don't need all of the data. I'm looking to retrieve all json object data&nbsp;from <strong>"type":"CC"</strong> part only (in this case 3rd object).</div><div style="font-size: 12pt;">&nbsp;</div><div style="font-size: 12pt;">I'm using json.net;</div><div style="font-size: 12pt;">&nbsp;</div><div style="font-size: 12pt;">Another thing. Sometimes, mydata.json file might generate&nbsp;3rd object "type":"CC" below twice or three times. However, the ID part&nbsp;on that CC will always be different.</div><div style="font-size: 12pt;">&nbsp;</div><div style="font-size: 12pt;">{<br /><strong><span style="color: #008000;">"type"</span>: <span style="color: #008000;">"CC"</span>,<br /><span style="color: #008000;">"Id"</span>: <span style="color: #008000;">"114"</span>,<br /><span style="color: #008000;">"service"</span>: <span style="color: #000080;">true</span>,<br /><span style="color: #008000;">"description"</span>: <span style="color: #008000;">""</span>,<br /><span style="color: #008000;">"imageUrl"</span>: <span style="color: #008000;">"http://www.somelink.com/file.jpg"</span>,<br /><span style="color: #008000;">"date"</span>: </strong><span style="color: #008000;"><strong>"1457611015000"</strong><br /></span>}&nbsp;</div><div style="font-size: 12pt;">&nbsp;</div><div style="font-size: 12pt;">If that to happen, I only need to retrieve data from the last "CC" object in this case.</div><div style="font-size: 12pt;">&nbsp;</div><div style="font-size: 12pt;">Another case might happen is that sometimes&nbsp;mydata.json&nbsp;file&nbsp;will generate only first two objects "AA" and "BB". If this happens (IF&nbsp;type "CC" is&nbsp;not printed)&nbsp;I need in the code to have IF() statement, to determine what to do.</div><div style="font-size: 12pt;">&nbsp;</div><div style="font-size: 12pt;">I very much need C# code to confirm (perhaps "success" label) that mydata.json&nbsp;content is loaded successfully before it will be&nbsp;shown on the window.</div><div style="font-size: 12pt;">&nbsp;</div><div style="font-size: 12pt;">Please guys, can someone help me with the code bit? I need something simple, less messy.</div><div style="font-size: 12pt;">&nbsp;</div><div style="font-size: 12pt;">I won't be able to give you a hug or contribute towards&nbsp;for your help,&nbsp;but definitely guarantee a genuine "Thank you" from a stranger. Hope this matters.&nbsp;</div><div style="font-size: 12pt;"></div>

Answers (6)