TJsonObject
Class
type TJsonObject = class(TJson)
Represents a JSON object. Contains 0 or more members that are name/value pairs. Members can be accessed by name or index.
Properties
MemberCount: Integer read;
Return the number of members in the object.
MemberName[Index: Integer]: WideString read write;
Set/return the name of the specified member.
MemberValue[Index: Integer]: TJson read write;
Set/return the value of the specified member.
Members[const Name: WideString]: TJson read write; default;
Set/return the specified member. Returns nil if not found.
NullItem[const Name: WideString]: TJsonNull read;
FalseItem[const Name: WideString]: TJsonFalse read;
TrueItem[const Name: WideString]: TJsonTrue read;
ObjectItem[const Name: WideString]: TJsonObject read;
StringItem[const Name: WideString]: TJsonString read;
ArrayItem[const Name: WideString]: TJsonArray read;
NumberItem[const Name: WideString]: TJsonNumber read;
Returns the specified member if the name is valid, and the type requested matches the contents.
Methods
constructor Create;
Creates a TJsonObject instance.
procedure DeleteAll;
Deletes all members.
procedure Delete(Index: Integer); overload;
procedure Delete(const Name: WideString); overload;
Deletes the specified member.
function Find(const Name: WideString): Integer;
Finds the index of the specified member. Returns -1 if not found.
function SetArray(const Name: WideString; ElementCount: Integer): TJsonArray;
procedure SetDateTime(const Name: WideString; const Value: TDateTime; Offset: Integer = 0);
procedure SetFalse(const Name: WideString);
function SetJson(const Name: WideString; Value: TJson): TJson;
procedure SetNull(const Name: WideString);
procedure SetNumber(const Name: WideString; Value: Double);
function SetObject(const Name: WideString): TJsonObject;
procedure SetString(const Name: WideString; const Value: WideString);
procedure SetTrue(const Name: WideString);
The Set methods create/convert the specified member to the specified type and value. SetArray, SetJson, and SetObject return instances of the newly modified elements for further manipulation.
Example
jObject = TJsonObject.Create 'Creates empty object
showmessage(jObject.MemberCount) 'displays 0
jObject.SetNull("Null")
showmessage(jObject.MemberCount) 'displays 1
jObject.SetFalse("False")
showmessage(jObject.MemberCount) 'displays 2
jObject.DeleteAll
showmessage(jObject.MemberCount) 'displays 0 |