System.JSON.TJSONObject.AddPair
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 */;
Propriétés
Type | Visibilité | Source | Unité | Parent |
---|---|---|---|---|
function | public | System.JSON.pas System.JSON.hpp |
System.JSON | TJSONObject |
Description
Ajoute une nouvelle paire à l'objet JSON en cours.
La paire à ajouter peut être spécifiée en tant que paire JSON TJSONPair, via le paramètre Pair, ou sous forme de deux partie distinctes de la paire JSON, spécifiées en tant que paramètres partie clé Str et partie valeur Val.
AddPair renvoie l'objet JSON obtenu. Si l'un des paramètres spécifiées est nil
d'une chaîne vide, AddPair renvoie l'objet JSON en cours.
L'extrait de code suivant montre comment écrire un objet JSON :
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;
Voici le contenu JSON généré :
{"consentement":{"decision":"NA","idPatient":{"ipp":1122368},"idStructure":300000000023887}}