Delphi DLL
Delphi DLL
Using JSON StringOf with Non-String Members
See more JSON Examples
If a JSON member is a boolean, integer, or null, usingStringOf will return its string representation.
Chilkat Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, JsonObject;
...
procedure TForm1.Button1Click(Sender: TObject);
var
json: HCkJsonObject;
a: PWideChar;
b: PWideChar;
c: PWideChar;
ival: Integer;
bval: Boolean;
hasNull: Boolean;
begin
// Create JSON with members of different data types.
json := CkJsonObject_Create();
CkJsonObject_UpdateInt(json,'a',123);
CkJsonObject_UpdateBool(json,'b',True);
CkJsonObject_UpdateNull(json,'c');
CkJsonObject_putEmitCompact(json,False);
Memo1.Lines.Add(CkJsonObject__emit(json));
// Resulting JSON:
// {
// "a": 123,
// "b": true,
// "c": null
// }
a := CkJsonObject__stringOf(json,'a');
Memo1.Lines.Add(a);
b := CkJsonObject__stringOf(json,'b');
Memo1.Lines.Add(b);
c := CkJsonObject__stringOf(json,'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 := CkJsonObject_IntOf(json,'a');
bval := CkJsonObject_BoolOf(json,'b');
hasNull := CkJsonObject_IsNullOf(json,'c');
CkJsonObject_Dispose(json);
end;