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
(PowerBuilder) 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 } }
integer li_rc oleobject loo_Json integer li_Success oleobject loo_SampleData loo_Json = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject") if li_rc < 0 then destroy loo_Json MessageBox("Error","Connecting to COM object failed") return end if loo_Json.EmitCompact = 0 // Assume the file contains the data as shown above.. li_Success = loo_Json.LoadFile("qa_data/json/sample2.json") if li_Success <> 1 then Write-Debug loo_Json.LastErrorText destroy loo_Json return end if // First navigate to the "sampleData" object: loo_SampleData = loo_Json.ObjectOf("sampleData") // Demonstrate BoolAt and BoolOf Write-Debug "hungry: " + string(loo_SampleData.BoolOf("hungry")) Write-Debug "hungry: " + string(loo_SampleData.BoolAt(2)) // StringOf returns the value as a string regardless of it's actual type: Write-Debug "pi: " + loo_SampleData.StringOf("pi") Write-Debug "answer: " + loo_SampleData.StringOf("answer") Write-Debug "withoutValue: " + loo_SampleData.StringOf("withoutValue") Write-Debug "hungry: " + loo_SampleData.StringOf("hungry") // Demonstrate IsNullOf / IsNullAt Write-Debug "withoutValue is null? " + string(loo_SampleData.IsNullOf("withoutValue")) Write-Debug "withoutValue is null? " + string(loo_SampleData.IsNullAt(3)) Write-Debug "apple is null? " + string(loo_SampleData.IsNullOf("apple")) Write-Debug "apple is null? " + string(loo_SampleData.IsNullAt(1)) // IntOf Write-Debug "answer: " + string(loo_SampleData.IntOf("answer")) // SetNullAt, SetNullOf // Set "pi" to null li_Success = loo_SampleData.SetNullAt(0) // Set "answer" to null li_Success = loo_SampleData.SetNullOf("answer") // Show the changes: Write-Debug loo_Json.Emit() // Restore pi and apple: li_Success = loo_SampleData.SetNumberAt(0,"3.14") li_Success = loo_SampleData.SetNumberOf("answer","42") // Show the changes: Write-Debug loo_Json.Emit() // Add a null value named "afterApple" just after "apple" li_Success = loo_SampleData.AddNullAt(2,"afterApple") // Add a boolean value just after "pi" li_Success = loo_SampleData.AddBoolAt(1,"afterPi",0) destroy loo_SampleData // Examine the changes.. Write-Debug loo_Json.Emit() destroy loo_Json |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.