System.JSON.TJSONObject.AddPair

Aus RAD Studio API Documentation
Wechseln zu: Navigation, Suche

Delphi

function AddPair(const Pair: TJSONPair): TJSONObject; overload;
function AddPair(const Str: TJSONString; const Val: TJSONValue): TJSONObject; overload;
function AddPair(const Str: string; const Val: TJSONValue): TJSONObject; overload;
function AddPair(const Str: string; const Val: string): TJSONObject; overload;

C++

TJSONObject* __fastcall AddPair(TJSONPair* const Pair)/* overload */;
TJSONObject* __fastcall AddPair(TJSONString* const Str, TJSONValue* const Val)/* overload */;
TJSONObject* __fastcall AddPair(const System::UnicodeString Str, TJSONValue* const Val)/* overload */;
TJSONObject* __fastcall AddPair(const System::UnicodeString Str, const System::UnicodeString Val)/* overload */;

Eigenschaften

Typ Sichtbarkeit Quelle Unit Übergeordnet
function public
System.JSON.pas
System.JSON.hpp
System.JSON TJSONObject


Beschreibung

Fügt dem aktuellen JSON-Objekt ein neues JSON-Paar hinzu.

Das hinzuzufügende JSON-Paar kann entweder als ein TJSONPair-JSON-Paar oder im Pair, oder als zwei separate Teile des JSON-Paars angegeben werden, die als Str key-Teil und Val value-Teil-Parameter angegeben sind.

AddPair gibt das erhaltene JSON-Objekt zurück. Wenn einer der angegebenen Parameter nil eines leeren Strins ist, dann gibt AddPair das aktuelle JSON-Objekt zurück.


Das folgende Codefragment zeigt, wie ein JSON-Objekt geschrieben wird:

uses System.json;

var
  Obj, ObjCons, ObjIpp: TJSONObject;

begin
  Obj := TJSONObject.Create;
  try
    ObjIpp := TJSONObject.Create;
    ObjIpp.AddPair('ipp', TJSONNumber.Create(1122368));

    ObjCons := TJSONObject.Create;
    ObjCons.AddPair('decision', 'NA');
    ObjCons.AddPair('idPatient', ObjIpp);
    ObjCons.AddPair('idStructure', TJSONNumber.Create(300000000023887));

    Obj.AddPair('consentement', ObjCons);
    Memo1.Lines.Add(Obj.ToJSON);
  finally
    Obj.Free;
  end;

end;

Das ist der erzeugte JSON-Inhalt:

{"consentement":{"decision":"NA","idPatient":{"ipp":1122368},"idStructure":300000000023887}}

Siehe auch