System.JSON.TJSONObject.AddPair

提供: RAD Studio API Documentation
移動先: 案内検索

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 */;

プロパティ

種類 可視性 ソース ユニット
function public
System.JSON.pas
System.JSON.hpp
System.JSON TJSONObject


説明

現在の JSON オブジェクトに新しい JSON ペアを追加します。

追加する JSON ペアは、TJSONPair JSON ペアとして、Pair パラメータとして渡されるか、Str key および Val value の各部分を表すパラメータで指定された、2 つの別個の JSON ペアのパーツとして渡されます。

AddPair は、取得された JSON オブジェクトを返します。指定されたパラメータのいずれかが空文字列の nil だった場合、AddPair は現在の JSON オブジェクトを返します。

次のコード スニペットは、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;

これは、生成された JSON コンテンツです:

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

関連項目