Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Delphi ActiveX) JSON: Miscellaneous OperationsDemonstrates a variety of JSON API methods. This example uses the following JSON document: { "alphabet": "abcdefghijklmnopqrstuvwxyz", "sampleData" : { "pi": 3.14, "apple": "juicy", "hungry": true, "withoutValue": null, "answer": 42 } }
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; success: Integer; sampleData: IChilkatJsonObject; begin json := TChilkatJsonObject.Create(Self); json.EmitCompact := 0; // Assume the file contains the data as shown above.. success := json.LoadFile('qa_data/json/sample2.json'); if (success <> 1) then begin Memo1.Lines.Add(json.LastErrorText); Exit; end; // First navigate to the "sampleData" object: sampleData := json.ObjectOf('sampleData'); // Demonstrate BoolAt and BoolOf Memo1.Lines.Add('hungry: ' + IntToStr(Ord(sampleData.BoolOf('hungry')))); Memo1.Lines.Add('hungry: ' + IntToStr(Ord(sampleData.BoolAt(2)))); // StringOf returns the value as a string regardless of it's actual type: Memo1.Lines.Add('pi: ' + sampleData.StringOf('pi')); Memo1.Lines.Add('answer: ' + sampleData.StringOf('answer')); Memo1.Lines.Add('withoutValue: ' + sampleData.StringOf('withoutValue')); Memo1.Lines.Add('hungry: ' + sampleData.StringOf('hungry')); // Demonstrate IsNullOf / IsNullAt Memo1.Lines.Add('withoutValue is null? ' + IntToStr(Ord(sampleData.IsNullOf('withoutValue')))); Memo1.Lines.Add('withoutValue is null? ' + IntToStr(Ord(sampleData.IsNullAt(3)))); Memo1.Lines.Add('apple is null? ' + IntToStr(Ord(sampleData.IsNullOf('apple')))); Memo1.Lines.Add('apple is null? ' + IntToStr(Ord(sampleData.IsNullAt(1)))); // IntOf Memo1.Lines.Add('answer: ' + IntToStr(sampleData.IntOf('answer'))); // SetNullAt, SetNullOf // Set "pi" to null success := sampleData.SetNullAt(0); // Set "answer" to null success := sampleData.SetNullOf('answer'); // Show the changes: Memo1.Lines.Add(json.Emit()); // Restore pi and apple: success := sampleData.SetNumberAt(0,'3.14'); success := sampleData.SetNumberOf('answer','42'); // Show the changes: Memo1.Lines.Add(json.Emit()); // Add a null value named "afterApple" just after "apple" success := sampleData.AddNullAt(2,'afterApple'); // Add a boolean value just after "pi" success := sampleData.AddBoolAt(1,'afterPi',0); // Examine the changes.. Memo1.Lines.Add(json.Emit()); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.