zoukankan      html  css  js  c++  java
  • Delphi调用REST

    Delphi调用REST很简单,首先在界面上放上:

    RESTClient1: TRESTClient;
    RESTRequest1: TRESTRequest;
    RESTResponse1: TRESTResponse;

    然后简单调用即可:

    RESTClient1.BaseURL:=edtURL.Text;
    RESTRequest1.Execute;
    memLog.Text:=RESTResponse1.Content;

    还可以对结果进行进一部处理,比如解析JSON:

    procedure TfrmMain.btnGetClick(Sender: TObject);
    var
      jo,jo2:TJSONObject;
      jv:TJSONValue;
      ja:TJSONArray;
      jp:TJSONPair;
      i:Integer;
    begin
      RESTClient1.BaseURL:=edtURL.Text;
      RESTRequest1.Execute;
      memLog.Text:=RESTResponse1.Content;
    
      jo:=TJSONObject.Create;
      ja:=jo.ParseJSONValue(RESTResponse1.Content) as TJSONArray;
      for jv in ja do
       begin
          jo2:=jv as TJSONObject;
          for i:=0 to jo2.Count-1 do
          begin
            jp:=jo2.Pairs[i];
            memLog.Lines.Add(jp.JsonString.ToString+':'+jp.JsonValue.ToString);
          end;
       end;
    
    end;

    在这里我使用的是Delphi自带的JSON解析,注意引用单元system.json。

  • 相关阅读:
    01Game
    面试题
    面试题
    面向对象笔记
    1212作业
    12011作业
    1210作业
    1206作业
    1205作业
    1204作业
  • 原文地址:https://www.cnblogs.com/GarfieldTom/p/4901001.html
Copyright © 2011-2022 走看看