Einzelnen Beitrag anzeigen

TiGü

Registriert seit: 6. Apr 2011
Ort: Berlin
3.060 Beiträge
 
Delphi 10.4 Sydney
 
#2

AW: PHP-Array als REST-Parameter

  Alt 4. Feb 2019, 12:44
Delphi-Quellcode:
function GetValue: string;
var
  JSONObj1, JSONObj2: TJSONObject;
  JSONArray: TJSONArray;
begin
  JSONArray := TJSONArray.Create;

  JSONObj1 := TJSONObject.Create;

  JSONObj1.AddPair(TJSONPair.Create('property', 'name'));
  JSONObj1.AddPair(TJSONPair.Create('value', '%beach%'));
  JSONObj1.AddPair(TJSONPair.Create('operator', TJSONNumber.Create(1)));

  JSONArray.AddElement(JSONObj1);

  JSONObj2 := TJSONObject.Create;
  JSONObj2.AddPair(TJSONPair.Create('property', 'active'));
  JSONObj2.AddPair(TJSONPair.Create('value', TJSONNumber.Create(1)));

  JSONArray.AddElement(JSONObj2);

  Result := JSONArray.ToJSON;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  RestClient: TRESTClient;
  Param: TRESTRequestParameter;
begin
  RestClient := TRESTClient.Create(Self);
  Param := RestClient.Params.AddItem;
  Param.Kind := TRESTRequestParameterKind.pkGETorPOST;
  // Die englische Doku ist in der Regel eher gefüllt als die deutsche Übersetzung:
  // http://docwiki.embarcadero.com/Libraries/Rio/en/REST.Types.TRESTRequestParameterOption
  Param.Options := Param.Options + [TRESTRequestParameterOption.poPHPArray];
  Param.name := 'filter';
  Param.Value := GetValue;
end;
Das finden und lösen der Speicherlecks ist Teil der Klausur!
Hab hier nur ein Tokyo zum zusammenbasteln, musst mal sehen ob das mit dem Array passt.
  Mit Zitat antworten Zitat