Advertisement
Guest User

delphi json sample

a guest
Jun 2nd, 2011
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 3.00 KB | None | 0 0
  1. unit Unit66;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Memo1: TMemo;
  12.     Button1: TButton;
  13.     procedure Button1Click(Sender: TObject);
  14.   private
  15.     { Private declarations }
  16.     procedure ParseString(const AString:string);
  17.   public
  18.     { Public declarations }
  19.   end;
  20.  
  21. var
  22.   Form1: TForm1;
  23.  
  24. implementation
  25.  
  26. Uses
  27.  DBXJSON;
  28.  
  29. {$R *.dfm}
  30.  
  31. const
  32. JsonStr=
  33. '{ "permalink" : "http://www.virustotal.com/file-scan/report.html?id=7b6b268cbca9d421aabba5f08533d3dcaba50e0f7887b07ef2bd66bf218b35ff-1304089592",'+
  34. '  "report" : [ "2011-04-29 15:06:32",'+
  35. '      { "AVG" : "Exploit_c.TVH",'+
  36. '        "AhnLab-V3" : "PDF/Exploit",'+
  37. '        "AntiVir" : "EXP/Pidief.UK",'+
  38. '        "Antiy-AVL" : "Trojan/win32.agent",'+
  39. '        "Avast" : "JS:Pdfka-gen",'+
  40. '        "Avast5" : "JS:Pdfka-gen",'+
  41. '        "BitDefender" : "Exploit.PDF-JS.Gen",'+
  42. '        "CAT-QuickHeal" : "",'+
  43. '        "ClamAV" : "",'+
  44. '        "Comodo" : "Exploit.JS.Pidief.~AWQ",'+
  45. '        "DrWeb" : "",'+
  46. '        "Emsisoft" : "Exploit.JS.Pdfka!IK",'+
  47. '        "F-Prot" : "",'+
  48. '        "F-Secure" : "Exploit:W32/Pidief.DEE",'+
  49. '        "Fortinet" : "",'+
  50. '        "GData" : "",'+
  51. '        "Ikarus" : "Exploit.JS.Pdfka",'+
  52. '        "Jiangmin" : "",'+
  53. '        "K7AntiVirus" : "",'+
  54. '        "Kaspersky" : "Exploit.JS.Pdfka.dnc",'+
  55. '        "McAfee" : "",'+
  56. '        "McAfee-GW-Edition" : "",'+
  57. '        "Microsoft" : "Exploit:Win32/Pdfjsc.NJ",'+
  58. '        "NOD32" : "PDF/Exploit.Pidief.PGD",'+
  59. '        "Norman" : "",'+
  60. '        "PCTools" : "Trojan.Pidief",'+
  61. '        "Panda" : "",'+
  62. '        "Prevx" : "",'+
  63. '        "Rising" : "",'+
  64. '        "SUPERAntiSpyware" : "",'+
  65. '        "Sophos" : "Troj/PDFJs-RD",'+
  66. '        "Symantec" : "Trojan.Pidief",'+
  67. '        "TheHacker" : "",'+
  68. '        "TrendMicro" : "TROJ_PIDIEF.VTG",'+
  69. '        "TrendMicro-HouseCall" : "TROJ_PIDIEF.VTG",'+
  70. '        "VBA32" : "",'+
  71. '        "VIPRE" : "Exploit.PDF-JS.Gen (v)",'+
  72. '        "ViRobot" : "PDF.S.Exploit.74634",'+
  73. '        "VirusBuster" : "",'+
  74. '        "eSafe" : "",'+
  75. '        "eTrust-Vet" : ""'+
  76. '      }'+
  77. '    ],'+
  78. '  "result" : 1'+
  79. '}';
  80.  
  81.  
  82. procedure TForm1.Button1Click(Sender: TObject);
  83. begin
  84.   ParseString(JsonStr);
  85. end;
  86.  
  87. procedure TForm1.ParseString(const AString: string);
  88. var
  89.   json          : TJSONObject;
  90.   jPair         : TJSONPair;
  91.   jValue        : TJSONValue;
  92.   jcValue       : TJSONValue;
  93.   l,i           : Integer;
  94. begin
  95.     json    := TJSONObject.ParseJSONValue(TEncoding.ASCII.GetBytes(AString),0) as TJSONObject;
  96.   try
  97.     jPair   := json.Get(1);
  98.     jValue := TJSONArray(jPair.JsonValue).Get(1);
  99.     l:=TJSONArray(jValue).Size;
  100.     for i:=0 to l-1 do
  101.     begin
  102.      jcValue := TJSONArray(jValue).Get(i);
  103.      jPair   := TJSONPair(jcValue);
  104.      Memo1.Lines.Add(Format('Antivirus %s Result %s',[jPair.JsonString.Value,jPair.JsonValue.Value]));
  105.     end;
  106.   finally
  107.      json.Free;
  108.   end;
  109. end;
  110.  
  111. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement