Hi!
Trying to add an TJSONArray
value results in null when TJSONObject
had been parsed from a string. Works fine when creating TJSONObject
from scratch.
This doesn't happen in VCL (using System.JSON
).
The following code runs in Web Core & VCL.
In Web Core (WebLib.JSON
), the btCreate
generates:
{"MyData":"123 Ok","MyNewData":"789 Ok","
MyArray":[1,2,3]}
while btParse
generates:
{"MyData":"123 Ok","MyNewData":"789 Ok","
MyArray":null}
In VCL (System.JSON
) both buttons generate the expected ToJSON
.
Attached both VCL & Web Core projects.
TJSONObjectAddArray VCL.zip (89.5 KB)
tjsonobjectaddarray.zip (7.0 KB)
procedure TMyForm.btCreateClick(Sender: TObject);
var
x : TJSONObject;
xa : TJSONArray;
begin
x := TJSONObject.Create;
x.AddPair('MyData','123 Ok');
x.AddPair('MyNewData','789 Ok');
xa := TJSONArray.Create;
xa.Add(1);
xa.Add(2);
xa.Add(3);
x.AddPair('MyArray', xa);
memo.Lines.Text := x.ToJSON;
x.Free;
end;
procedure TMyForm.btParseClick(Sender: TObject);
var
x : TJSONObject;
xa : TJSONArray;
begin
x := TJSONObject.ParseJSONValue('{"MyData":"123 Ok"}') as TJSONObject;
x.AddPair('MyNewData','789 Ok');
xa := TJSONArray.Create;
xa.Add(1);
xa.Add(2);
xa.Add(3);
x.AddPair('MyArray', xa);
memo.Lines.Text := x.ToJSON;
x.Free;
end;