Sample code for 30+ languages & platforms
Delphi ActiveX

Using JSON StringOf with Non-String Members

See more JSON Examples

If a JSON member is a boolean, integer, or null, using StringOf will return its string representation.

Chilkat Delphi ActiveX Downloads

Delphi ActiveX
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Chilkat_TLB;

...

procedure TForm1.Button1Click(Sender: TObject);
var
json: TChilkatJsonObject;
a: WideString;
b: WideString;
c: WideString;
ival: Integer;
bval: Integer;
hasNull: Integer;

begin
// Create JSON with members of different data types.
json := TChilkatJsonObject.Create(Self);

json.UpdateInt('a',123);
json.UpdateBool('b',1);
json.UpdateNull('c');

json.EmitCompact := 0;
Memo1.Lines.Add(json.Emit());

// Resulting JSON:
// {
//   "a": 123,
//   "b": true,
//   "c": null
// }

a := json.StringOf('a');
Memo1.Lines.Add(a);

b := json.StringOf('b');
Memo1.Lines.Add(b);

c := json.StringOf('c');
Memo1.Lines.Add(c);

// Output

// 123
// true
// null

// If you want to get the integer, boolean, or null value
// you need to use the methods matching the data type
ival := json.IntOf('a');
bval := json.BoolOf('b');
hasNull := json.IsNullOf('c');
end;