Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
来自virustotal api的Json解析结果_Json_Delphi_Delphi 2010_Antivirus - Fatal编程技术网

来自virustotal api的Json解析结果

来自virustotal api的Json解析结果,json,delphi,delphi-2010,antivirus,Json,Delphi,Delphi 2010,Antivirus,今天,我在玩virustotal api,同时以以下形式返回结果: 我想知道如何解析此结果,以填充如下备忘录: Memo1.Lines.Add(Format('Antivirus: %0s Result: %1s', [...])); 嗯,我真的不知道所有可能存在的JSon组件,也许有人可以告诉我正确的方向 最亲切的问候 H.Meiser我推荐开源JSON库和在线JSON检查器,如or(此编辑器有一个非常有用的选项,可将类型信息添加到视图中)解析JSON字符串并不困难,您可以使用自delphi

今天,我在玩virustotal api,同时以以下形式返回结果:

我想知道如何解析此结果,以填充如下备忘录:

Memo1.Lines.Add(Format('Antivirus: %0s Result: %1s', [...]));
嗯,我真的不知道所有可能存在的JSon组件,也许有人可以告诉我正确的方向

最亲切的问候


H.Meiser

我推荐开源JSON库和在线JSON检查器,如or(此编辑器有一个非常有用的选项,可将类型信息添加到视图中)

解析JSON字符串并不困难,您可以使用自delphi 2010年以来包含的单元

检查此示例代码

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;

作为补充建议,您必须阅读Json教程以了解如何解释Json格式,并且必须准备好使用任何可用的库。

您使用的是哪个版本的delphi?这不需要Json或其他任何东西。这是一种非常简单的文本解析,只需调用几次
Pos
即可提取相关文本(
[]
之间的部分),使用
CommaText
StrictDelimiters
TStringList
和一个非常简单的循环即可将每行的两半(AV名称和输出)分开. 为什么要为这么简单的工作增加外部库的复杂性?例如,虽然我得到的结果(Json)将来可能会改变,所以它可能是可变的?至少学习如何用json解析没有什么错?我同意你阅读json的观点。我已经测试了你的过程,但它给了我一个访问冲突?我用你发布的相同字符串测试了代码。您在哪一行遇到问题?调用ParseString时直接引发访问冲突?解析字符串(Memo2.Text);这一行上引发的访问冲突的结果相同:jValue:=TJSONArray(jPair.JsonValue.Get(1)@HMeiser,D2010中的JSON解析器不符合JSON规范。它至少违反了两个条款:。不要使用它。这两个JavaScript应用程序都没有任何用处。JSON是专门为人性化设计的。
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;