Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2022-10

JSONToObject with array of any type

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Hairy Pixels

I have some JSON with a “arguments” value which can be an array of JSON type. When it’s received and parsed with TJSONDeStreamer.JSONToObject how can I represent this “any” type? I tried using TJSONArray but it always returns an empty array.

The JSON is parse:

{
"command": "do_stuff",
"arguments": ["path", 1, 80]
}

The object to stream to:

  TExecuteCommandParams = class
    private
      fCommand: String;
      fArguments: TJSONArray;
    published
      property command: String read fCommand write fCommand;
      property arguments: TJSONArray read fArguments write fArguments;
  end;

Regards,
Ryan Joseph

Michael Van Canneyt
to Hairy Pixels
Hairy Pixels wrote 19 lines
I have some JSON with a “arguments” value which can be an array of JSON type. When it’s received and parsed with TJSONDeStreamer.JSONToObject how can I represent this “any” type? I tried using TJSONArray but it always returns an empty array. The JSON is parse: { "command": "do_stuff", "arguments": ["path", 1, 80] } The object to stream to: TExecuteCommandParams = class private fCommand: String; fArguments: TJSONArray; published property command: String read fCommand write fCommand; property arguments: TJSONArray read fArguments write fArguments; end;

The standard streamer does not allow this (yet). It is on my todo list to improve it.

Michael.