mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 22:49:23 +02:00
* Add null in Array/Object if an element is Nil.
git-svn-id: trunk@34537 -
This commit is contained in:
parent
5be2dfd9c8
commit
0af46b90aa
@ -623,7 +623,6 @@ Resourcestring
|
|||||||
SErrCannotConvertFromObject = 'Cannot convert data from object value';
|
SErrCannotConvertFromObject = 'Cannot convert data from object value';
|
||||||
SErrCannotConvertToObject = 'Cannot convert data to object value';
|
SErrCannotConvertToObject = 'Cannot convert data to object value';
|
||||||
SErrInvalidFloat = 'Invalid float value : %s';
|
SErrInvalidFloat = 'Invalid float value : %s';
|
||||||
SErrInvalidInteger = 'Invalid float value : %s';
|
|
||||||
SErrCannotSetNotIsNull = 'IsNull cannot be set to False';
|
SErrCannotSetNotIsNull = 'IsNull cannot be set to False';
|
||||||
SErrCannotAddArrayTwice = 'Adding an array object to an array twice is not allowed';
|
SErrCannotAddArrayTwice = 'Adding an array object to an array twice is not allowed';
|
||||||
SErrCannotAddObjectTwice = 'Adding an object to an array twice is not allowed';
|
SErrCannotAddObjectTwice = 'Adding an object to an array twice is not allowed';
|
||||||
@ -1074,7 +1073,7 @@ procedure TJSONData.DumpJSON(S: TStream);
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
Var
|
Var
|
||||||
I,C : Integer;
|
I: Integer;
|
||||||
O : TJSONObject;
|
O : TJSONObject;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@ -2049,13 +2048,20 @@ function TJSONArray.GetAsJSON: TJSONStringType;
|
|||||||
Var
|
Var
|
||||||
I : Integer;
|
I : Integer;
|
||||||
Sep : String;
|
Sep : String;
|
||||||
|
D : TJSONData;
|
||||||
|
V : TJSONStringType;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Sep:=TJSONData.FElementSep;
|
Sep:=TJSONData.FElementSep;
|
||||||
Result:='[';
|
Result:='[';
|
||||||
For I:=0 to Count-1 do
|
For I:=0 to Count-1 do
|
||||||
begin
|
begin
|
||||||
Result:=Result+Items[i].AsJSON;
|
D:=Items[i];
|
||||||
|
if D<>Nil then
|
||||||
|
V:=D.AsJSON
|
||||||
|
else
|
||||||
|
V:='null';
|
||||||
|
Result:=Result+V;
|
||||||
If (I<Count-1) then
|
If (I<Count-1) then
|
||||||
Result:=Result+Sep;
|
Result:=Result+Sep;
|
||||||
end;
|
end;
|
||||||
@ -2093,6 +2099,9 @@ begin
|
|||||||
begin
|
begin
|
||||||
if MultiLine then
|
if MultiLine then
|
||||||
Result:=Result+Ind;
|
Result:=Result+Ind;
|
||||||
|
if Items[i]=Nil then
|
||||||
|
Result:=Result+'null'
|
||||||
|
else
|
||||||
Result:=Result+Items[i].DoFormatJSON(Options,CurrentIndent+Indent,Indent);
|
Result:=Result+Items[i].DoFormatJSON(Options,CurrentIndent+Indent,Indent);
|
||||||
If (I<Count-1) then
|
If (I<Count-1) then
|
||||||
if MultiLine then
|
if MultiLine then
|
||||||
@ -2671,6 +2680,8 @@ function TJSONObject.GetAsJSON: TJSONStringType;
|
|||||||
Var
|
Var
|
||||||
I : Integer;
|
I : Integer;
|
||||||
Sep : String;
|
Sep : String;
|
||||||
|
V : TJSONStringType;
|
||||||
|
D : TJSONData;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Sep:=TJSONData.FElementSep;
|
Sep:=TJSONData.FElementSep;
|
||||||
@ -2679,7 +2690,12 @@ begin
|
|||||||
begin
|
begin
|
||||||
If (Result<>'') then
|
If (Result<>'') then
|
||||||
Result:=Result+Sep;
|
Result:=Result+Sep;
|
||||||
Result:=Result+FElementStart+StringToJSONString(Names[i])+FElementEnd+Items[I].AsJSON;
|
D:=Items[i];
|
||||||
|
if Assigned(D) then
|
||||||
|
V:=Items[I].AsJSON
|
||||||
|
else
|
||||||
|
V:='null';
|
||||||
|
Result:=Result+FElementStart+StringToJSONString(Names[i])+FElementEnd+V;
|
||||||
end;
|
end;
|
||||||
If (Result<>'') then
|
If (Result<>'') then
|
||||||
Result:=FObjStartSep+Result+FObjEndSep
|
Result:=FObjStartSep+Result+FObjEndSep
|
||||||
@ -2807,6 +2823,9 @@ Var
|
|||||||
S : TJSONStringType;
|
S : TJSONStringType;
|
||||||
MultiLine,UseQuotes, SkipWhiteSpace : Boolean;
|
MultiLine,UseQuotes, SkipWhiteSpace : Boolean;
|
||||||
NSep,Sep,Ind : String;
|
NSep,Sep,Ind : String;
|
||||||
|
V : TJSONStringType;
|
||||||
|
D : TJSONData;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result:='';
|
Result:='';
|
||||||
UseQuotes:=Not (foDoNotQuoteMembers in options);
|
UseQuotes:=Not (foDoNotQuoteMembers in options);
|
||||||
@ -2833,7 +2852,12 @@ begin
|
|||||||
S:=StringToJSONString(Names[i]);
|
S:=StringToJSONString(Names[i]);
|
||||||
If UseQuotes then
|
If UseQuotes then
|
||||||
S:='"'+S+'"';
|
S:='"'+S+'"';
|
||||||
Result:=Result+S+NSep+Items[I].DoFormatJSON(Options,CurrentIndent,Indent);
|
D:=Items[i];
|
||||||
|
if D=Nil then
|
||||||
|
V:='null'
|
||||||
|
else
|
||||||
|
v:=Items[I].DoFormatJSON(Options,CurrentIndent,Indent);
|
||||||
|
Result:=Result+S+NSep+V;
|
||||||
end;
|
end;
|
||||||
If (Result<>'') then
|
If (Result<>'') then
|
||||||
begin
|
begin
|
||||||
|
Loading…
Reference in New Issue
Block a user