mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 02:59:13 +02:00
* Do not allow duplicate keys in JSONObject
git-svn-id: trunk@38908 -
This commit is contained in:
parent
b8378ef774
commit
f540dbfab3
@ -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);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<CONFIG>
|
<CONFIG>
|
||||||
<ProjectOptions>
|
<ProjectOptions>
|
||||||
<Version Value="10"/>
|
<Version Value="11"/>
|
||||||
<General>
|
<General>
|
||||||
<Flags>
|
<Flags>
|
||||||
<SaveOnlyProjectUnits Value="True"/>
|
<SaveOnlyProjectUnits Value="True"/>
|
||||||
@ -21,10 +21,18 @@
|
|||||||
</PublishOptions>
|
</PublishOptions>
|
||||||
<RunParams>
|
<RunParams>
|
||||||
<local>
|
<local>
|
||||||
<FormatVersion Value="1"/>
|
|
||||||
<CommandLineParams Value="--suite=TTestParser.TestArray"/>
|
<CommandLineParams Value="--suite=TTestParser.TestArray"/>
|
||||||
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
|
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
|
||||||
</local>
|
</local>
|
||||||
|
<FormatVersion Value="2"/>
|
||||||
|
<Modes Count="1">
|
||||||
|
<Mode0 Name="default">
|
||||||
|
<local>
|
||||||
|
<CommandLineParams Value="--suite=TTestParser.TestArray"/>
|
||||||
|
<LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
|
||||||
|
</local>
|
||||||
|
</Mode0>
|
||||||
|
</Modes>
|
||||||
</RunParams>
|
</RunParams>
|
||||||
<RequiredPackages Count="1">
|
<RequiredPackages Count="1">
|
||||||
<Item1>
|
<Item1>
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user