Десериализация JSON - C# (190667)

Узнай цену своей работы

Формулировка задачи:

Имеется ответ от сервера в Json
Листинг программы
  1. { "error_message" : false,
  2. "result" : [ { "AVG Free" : "OK" },
  3. { "Avast" : "OK" },
  4. { "AntiVir (Avira)" : "OK" },
  5. { "BitDefender" : "OK" },
  6. { "Clam Antivirus" : "OK" },
  7. { "COMODO Internet Security" : "OK" },
  8. { "Dr.Web" : "OK" },
  9. { "eTrust-Vet" : "OK" },
  10. { "F-PROT Antivirus" : "OK" },
  11. { "F-Secure Internet Security" : "OK" },
  12. { "G Data" : "OK" },
  13. { "IKARUS Security" : "OK" },
  14. { "Kaspersky Antivirus" : "OK" },
  15. { "McAfee" : "OK" },
  16. { "MS Security Essentials" : "OK" },
  17. { "ESET NOD32" : "OK" },
  18. { "Norman" : "OK" },
  19. { "Norton Antivirus" : "OK" },
  20. { "Panda Security" : "OK" },
  21. { "A-Squared" : "OK" },
  22. { "Quick Heal Antivirus" : "OK" },
  23. { "Solo Antivirus" : "OK" },
  24. { "Sophos" : "OK" },
  25. { "Trend Micro Internet Security" : "OK" },
  26. { "VBA32 Antivirus" : "OK" },
  27. { "Zoner AntiVirus" : "OK" },
  28. { "Ad-Aware" : "OK" },
  29. { "BullGuard" : "OK" },
  30. { "FortiClient" : "OK" },
  31. { "K7 Ultimate" : "OK" },
  32. { "NANO Antivirus" : "OK" },
  33. { "Panda CommandLine" : "OK" },
  34. { "SUPERAntiSpyware" : "OK" },
  35. { "Twister Antivirus" : "OK" },
  36. { "VIPRE" : "OK" }
  37. ],
  38. "status" : 1,
  39. "url" : "http://site.com/info/detail/659d7ab69c4d4aca9cf976233dd86050"
  40. }
Как правильно сделать дисериализацию. Инфы прочитал много ни ни чего не выходит (

Решение задачи: «Десериализация JSON»

textual
Листинг программы
  1.  public void ScanText(string token, string file)
  2.         {
  3.             try
  4.             {
  5.                 WebClient wc = new WebClient();
  6.                 wc.UploadFileCompleted += new UploadFileCompletedEventHandler(getTextResults);
  7.                 wc.UploadFileAsync(new Uri("http://ышеюсщь/api.php?auth_token&type=text"), "POST", file);
  8.                 while (wc.IsBusy)
  9.                 {
  10.                     Application.DoEvents();
  11.                 }
  12.             }
  13.             catch (Exception ex)
  14.             {
  15.                 MessageBox.Show(ex.Message);
  16.             }
  17.         }
  18.  
  19.         private void getTextResults(object sender, System.Net.UploadFileCompletedEventArgs e)
  20.         {
  21.             FileName = Path.GetFileName(textBox1.Text);
  22.             string response = System.Text.Encoding.UTF8.GetString(e.Result);
  23.             Dictionary<string, string> dict = new JavaScriptSerializer().Deserialize<Dictionary<string, string>>(response);
  24.             string result = dict["result"];
  25.             string url = dict["url"];
  26.             dict.Remove("url");
  27.             dict.Remove("result");
  28.             foreach (KeyValuePair<string, string> antiVirus in dict)
  29.             {
  30.                 string name = antiVirus.Key;
  31.                 string detection = antiVirus.Value;
  32.                 ListViewItem antiV = listView1.Items.Add(name);
  33.                 antiV.SubItems.Add(detection);
  34.                 antiV.ForeColor = Color.Red;
  35.                 if (detection.ToLower().Contains("ok"))
  36.                 {
  37.                     antiV.ForeColor = Color.Green;
  38.                 }
  39.                
  40.             }
  41.  
  42.              textBox2.Text = url;

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

8   голосов , оценка 3.875 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут