Десериализация JSON - C# (190667)
Формулировка задачи:
Имеется ответ от сервера в Json
Как правильно сделать дисериализацию. Инфы прочитал много ни ни чего не выходит (
Листинг программы
- { "error_message" : false,
- "result" : [ { "AVG Free" : "OK" },
- { "Avast" : "OK" },
- { "AntiVir (Avira)" : "OK" },
- { "BitDefender" : "OK" },
- { "Clam Antivirus" : "OK" },
- { "COMODO Internet Security" : "OK" },
- { "Dr.Web" : "OK" },
- { "eTrust-Vet" : "OK" },
- { "F-PROT Antivirus" : "OK" },
- { "F-Secure Internet Security" : "OK" },
- { "G Data" : "OK" },
- { "IKARUS Security" : "OK" },
- { "Kaspersky Antivirus" : "OK" },
- { "McAfee" : "OK" },
- { "MS Security Essentials" : "OK" },
- { "ESET NOD32" : "OK" },
- { "Norman" : "OK" },
- { "Norton Antivirus" : "OK" },
- { "Panda Security" : "OK" },
- { "A-Squared" : "OK" },
- { "Quick Heal Antivirus" : "OK" },
- { "Solo Antivirus" : "OK" },
- { "Sophos" : "OK" },
- { "Trend Micro Internet Security" : "OK" },
- { "VBA32 Antivirus" : "OK" },
- { "Zoner AntiVirus" : "OK" },
- { "Ad-Aware" : "OK" },
- { "BullGuard" : "OK" },
- { "FortiClient" : "OK" },
- { "K7 Ultimate" : "OK" },
- { "NANO Antivirus" : "OK" },
- { "Panda CommandLine" : "OK" },
- { "SUPERAntiSpyware" : "OK" },
- { "Twister Antivirus" : "OK" },
- { "VIPRE" : "OK" }
- ],
- "status" : 1,
- "url" : "http://site.com/info/detail/659d7ab69c4d4aca9cf976233dd86050"
- }
Решение задачи: «Десериализация JSON»
textual
Листинг программы
- public void ScanText(string token, string file)
- {
- try
- {
- WebClient wc = new WebClient();
- wc.UploadFileCompleted += new UploadFileCompletedEventHandler(getTextResults);
- wc.UploadFileAsync(new Uri("http://ышеюсщь/api.php?auth_token&type=text"), "POST", file);
- while (wc.IsBusy)
- {
- Application.DoEvents();
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- private void getTextResults(object sender, System.Net.UploadFileCompletedEventArgs e)
- {
- FileName = Path.GetFileName(textBox1.Text);
- string response = System.Text.Encoding.UTF8.GetString(e.Result);
- Dictionary<string, string> dict = new JavaScriptSerializer().Deserialize<Dictionary<string, string>>(response);
- string result = dict["result"];
- string url = dict["url"];
- dict.Remove("url");
- dict.Remove("result");
- foreach (KeyValuePair<string, string> antiVirus in dict)
- {
- string name = antiVirus.Key;
- string detection = antiVirus.Value;
- ListViewItem antiV = listView1.Items.Add(name);
- antiV.SubItems.Add(detection);
- antiV.ForeColor = Color.Red;
- if (detection.ToLower().Contains("ok"))
- {
- antiV.ForeColor = Color.Green;
- }
- }
- textBox2.Text = url;
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д