System.JSON.TJSONObject.AddPair

From RAD Studio API Documentation
Jump to: navigation, search

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;
function AddPair(const Str: string; const Val: Int64): TJSONObject; overload;
function AddPair(const Str: string; const Val: Integer): TJSONObject; overload;
function AddPair(const Str: string; const Val: Double): TJSONObject; overload;
function AddPair(const Str: string; const Val: Boolean): 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 */;
TJSONObject* __fastcall AddPair(const System::UnicodeString Str, const __int64 Val)/* overload */;
TJSONObject* __fastcall AddPair(const System::UnicodeString Str, const int Val)/* overload */;
TJSONObject* __fastcall AddPair(const System::UnicodeString Str, const double Val)/* overload */;
TJSONObject* __fastcall AddPair(const System::UnicodeString Str, const bool Val);
TJSONObject* __fastcall AddPair(const System::UnicodeString Str, const char* Val) {

Properties

Type Visibility Source Unit Parent
function public
System.JSON.pas
System.JSON.hpp
System.JSON TJSONObject

Description

Adds a new JSON pair to the current JSON object.

The JSON pair to be added can either be given as a TJSONPair JSON pair, through the Pair parameter, or as two separate parts of JSON pair, specified as the Str key part and Val value part parameters.

AddPair returns the obtained JSON object. If any of the specified parameters is nil of an empty string, then AddPair returns the current JSON object.

The following code snippet shows how to write a JSON object:

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;

This is the JSON content generated:

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

See Also