Json parse result from virustotal api

半城伤御伤魂 提交于 2019-12-05 08:53:15

Parsing Json string is not difficult, you can use the DBXJSON unit included since delphi 2010.

check this sample code

Uses
  DBXJSON;

procedure TForm1.ParseString(const AString: string);
var
  json          : TJSONObject;
  jPair         : TJSONPair;
  jValue        : TJSONValue;
  jcValue       : TJSONValue;
  l,i           : Integer;
begin
    json    := TJSONObject.ParseJSONValue(TEncoding.ASCII.GetBytes(AString),0) as TJSONObject;
  try
    //get the pair to evaluate in this case the index is 1
    jPair   := json.Get(1);
    //cast the JsonValue to TJSONArray to access the elements of the array
    jValue := TJSONArray(jPair.JsonValue).Get(1);
    l:=TJSONArray(jValue).Size;
    for i:=0 to l-1 do
    begin
     //get the i element of the array 
     jcValue := TJSONArray(jValue).Get(i);
     //get the pair pointing to the i element 
     jPair   := TJSONPair(jcValue);
     //show the result 
     Memo1.Lines.Add(Format('Antivirus %s Result %s',[jPair.JsonString.Value,jPair.JsonValue.Value]));
    end;
  finally
     json.Free;
  end;
end;

As additional recommendation you must read a Json tutorial to learn how interpret the Json format and in this way you must be preparated to use any library available.

I recommend the open source JSON library SuperObject and online JSON inspectors like http://jsonviewer.stack.hu/ or http://json.parser.online.fr/ (this editor has a very useful option which adds type information to the view)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!