Jason-X
Jason-X

Reputation: 39

Create json array of records with Delphi

I'm trying to create a json with multiple records by following this example: Generate a sample JSON with an array in it in Delphi XE5 must be the same way, except that when I add the array to the object

JSonObj.AddPair (TJSONPair.Create ('records', TJSONArray));

returns the error:

"There is the overloaded version of 'Create' that can be called with arguments These"

How do I add to the array object? If I convert an array to string and add, to receive the amounts can not treat as an array ...

Upvotes: 0

Views: 1815

Answers (1)

Rob Kennedy
Rob Kennedy

Reputation: 163357

You're passing it the class reference for a JSON array. You need to pass it an instance.

arr := TJSONArray.Create;
JSONObj.AddPair(TJSONPair.Create('records', arr));

Look carefully at the answers in the question you link to, and you'll see this is exactly what they're doing, too.

Upvotes: 3

Related Questions