Answer the question
In order to leave comments, you need to log in
How to create JSON in Delphi XE?
Good day to all! Please tell me how to create a record like this using DBXJSON :
I wrote a simple code, but when it is executed, "Invalid Pointer operation" falls out
[{"foo":"bar"},{"foo":"bar"}]
var
JS : TJSONObject;
JSA : TJSONArray;
JSP : TJSONPair;
begin
JS := TJSONObject.Create;
JSA := TJSONArray.Create;
JSP := TJSONPair.Create('Array', JSA);
JS.AddPair(JSP);
writeln(JS.ToString);
JSP.Free;
JS.Free;
JSA.Free;
readln;
end.
Answer the question
In order to leave comments, you need to log in
This is an array of objects. So, we create an array and add objects to it. Is it logical? Yes, I think so.
var
JSA : TJSONArray;
JS : TJSONObject;
begin
JSA := TJSONArray.Create;
JS := TJSONObject.Create;
JS.AddPair('foo', 'bar');
JSA.Add(JS);
JS := TJSONObject.Create;
JS.AddPair('foo', 'bar');
JSA.Add(JS);
writeln(JSA.ToString);
JSA.Free;
readln;
end.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question