|
@@ -470,6 +470,7 @@ Type
|
|
ObjEndSeps : Array[Boolean] of TJSONStringType = (' }','}');
|
|
ObjEndSeps : Array[Boolean] of TJSONStringType = (' }','}');
|
|
Class var FUnquotedMemberNames: Boolean;
|
|
Class var FUnquotedMemberNames: Boolean;
|
|
Class var FObjStartSep,FObjEndSep,FElementEnd,FElementStart : TJSONStringType;
|
|
Class var FObjStartSep,FObjEndSep,FElementEnd,FElementStart : TJSONStringType;
|
|
|
|
+ function DoAdd(const AName: TJSONStringType; AValue: TJSONData; FreeOnError: Boolean=True): Integer;
|
|
Class procedure DetermineElementQuotes;
|
|
Class procedure DetermineElementQuotes;
|
|
Private
|
|
Private
|
|
FHash : TFPHashObjectList; // Careful : Names limited to 255 chars.
|
|
FHash : TFPHashObjectList; // Careful : Names limited to 255 chars.
|
|
@@ -638,6 +639,7 @@ Resourcestring
|
|
SErrOddNumber = 'TJSONObject must be constructed with name,value pairs';
|
|
SErrOddNumber = 'TJSONObject must be constructed with name,value pairs';
|
|
SErrNameMustBeString = 'TJSONObject constructor element name at pos %d is not a string';
|
|
SErrNameMustBeString = 'TJSONObject constructor element name at pos %d is not a string';
|
|
SErrNonexistentElement = 'Unknown object member: "%s"';
|
|
SErrNonexistentElement = 'Unknown object member: "%s"';
|
|
|
|
+ SErrDuplicateValue = 'Duplicate object member: "%s"';
|
|
SErrPathElementNotFound = 'Path "%s" invalid: element "%s" not found.';
|
|
SErrPathElementNotFound = 'Path "%s" invalid: element "%s" not found.';
|
|
SErrWrongInstanceClass = 'Cannot set instance class: %s does not descend from %s.';
|
|
SErrWrongInstanceClass = 'Cannot set instance class: %s does not descend from %s.';
|
|
SErrNoParserHandler = 'No JSON parser handler installed. Recompile your project with the jsonparser unit included';
|
|
SErrNoParserHandler = 'No JSON parser handler installed. Recompile your project with the jsonparser unit included';
|
|
@@ -2943,58 +2945,69 @@ begin
|
|
FHash.Clear;
|
|
FHash.Clear;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+function TJSONObject.DoAdd(const AName: TJSONStringType; AValue: TJSONData; FreeOnError : Boolean = True): Integer;
|
|
|
|
+begin
|
|
|
|
+ if (IndexOfName(aName)<>-1) then
|
|
|
|
+ begin
|
|
|
|
+ if FreeOnError then
|
|
|
|
+ FreeAndNil(AValue);
|
|
|
|
+ DoError(SErrDuplicateValue,[aName]);
|
|
|
|
+ end;
|
|
|
|
+ Result:=FHash.Add(AName,AValue);
|
|
|
|
+end;
|
|
|
|
+
|
|
function TJSONObject.Add(const AName: TJSONStringType; AValue: TJSONData
|
|
function TJSONObject.Add(const AName: TJSONStringType; AValue: TJSONData
|
|
): Integer;
|
|
): Integer;
|
|
begin
|
|
begin
|
|
- Result:=FHash.Add(AName,AValue);
|
|
|
|
|
|
+ Result:=DoAdd(aName,AValue,False);
|
|
end;
|
|
end;
|
|
|
|
|
|
function TJSONObject.Add(const AName: TJSONStringType; AValue: Boolean
|
|
function TJSONObject.Add(const AName: TJSONStringType; AValue: Boolean
|
|
): Integer;
|
|
): Integer;
|
|
begin
|
|
begin
|
|
- Result:=Add(AName,CreateJSON(AValue));
|
|
|
|
|
|
+ Result:=DoAdd(AName,CreateJSON(AValue));
|
|
end;
|
|
end;
|
|
|
|
|
|
function TJSONObject.Add(const AName: TJSONStringType; AValue: TJSONFloat): Integer;
|
|
function TJSONObject.Add(const AName: TJSONStringType; AValue: TJSONFloat): Integer;
|
|
begin
|
|
begin
|
|
- Result:=Add(AName,CreateJSON(AValue));
|
|
|
|
|
|
+ Result:=DoAdd(AName,CreateJSON(AValue));
|
|
end;
|
|
end;
|
|
|
|
|
|
function TJSONObject.Add(const AName, AValue: TJSONStringType): Integer;
|
|
function TJSONObject.Add(const AName, AValue: TJSONStringType): Integer;
|
|
begin
|
|
begin
|
|
- Result:=Add(AName,CreateJSON(AValue));
|
|
|
|
|
|
+ Result:=DoAdd(AName,CreateJSON(AValue));
|
|
end;
|
|
end;
|
|
|
|
|
|
function TJSONObject.Add(const AName: String; AValue: TJSONUnicodeStringType
|
|
function TJSONObject.Add(const AName: String; AValue: TJSONUnicodeStringType
|
|
): Integer;
|
|
): Integer;
|
|
begin
|
|
begin
|
|
- Result:=Add(AName,CreateJSON(AValue));
|
|
|
|
|
|
+ Result:=DoAdd(AName,CreateJSON(AValue));
|
|
end;
|
|
end;
|
|
|
|
|
|
function TJSONObject.Add(const AName: TJSONStringType; Avalue: Integer): Integer;
|
|
function TJSONObject.Add(const AName: TJSONStringType; Avalue: Integer): Integer;
|
|
begin
|
|
begin
|
|
- Result:=Add(AName,CreateJSON(AValue));
|
|
|
|
|
|
+ Result:=DoAdd(AName,CreateJSON(AValue));
|
|
end;
|
|
end;
|
|
|
|
|
|
function TJSONObject.Add(const AName: TJSONStringType; Avalue: Int64): Integer;
|
|
function TJSONObject.Add(const AName: TJSONStringType; Avalue: Int64): Integer;
|
|
begin
|
|
begin
|
|
- Result:=Add(AName,CreateJSON(AValue));
|
|
|
|
|
|
+ Result:=DoAdd(AName,CreateJSON(AValue));
|
|
end;
|
|
end;
|
|
|
|
|
|
function TJSONObject.Add(const AName: TJSONStringType; Avalue: QWord): Integer;
|
|
function TJSONObject.Add(const AName: TJSONStringType; Avalue: QWord): Integer;
|
|
begin
|
|
begin
|
|
- Result:=Add(AName,CreateJSON(AValue));
|
|
|
|
|
|
+ Result:=DoAdd(AName,CreateJSON(AValue));
|
|
end;
|
|
end;
|
|
|
|
|
|
function TJSONObject.Add(const AName: TJSONStringType): Integer;
|
|
function TJSONObject.Add(const AName: TJSONStringType): Integer;
|
|
begin
|
|
begin
|
|
- Result:=Add(AName,CreateJSON);
|
|
|
|
|
|
+ Result:=DoAdd(AName,CreateJSON);
|
|
end;
|
|
end;
|
|
|
|
|
|
function TJSONObject.Add(const AName: TJSONStringType; AValue: TJSONArray
|
|
function TJSONObject.Add(const AName: TJSONStringType; AValue: TJSONArray
|
|
): Integer;
|
|
): Integer;
|
|
begin
|
|
begin
|
|
- Result:=Add(AName,TJSONData(AValue));
|
|
|
|
|
|
+ Result:=DoAdd(AName,TJSONData(AValue),False);
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TJSONObject.Delete(Index: Integer);
|
|
procedure TJSONObject.Delete(Index: Integer);
|