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
(Lianja) 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 } }
loJson = createobject("CkJsonObject") loJson.EmitCompact = .F. // Assume the file contains the data as shown above.. llSuccess = loJson.LoadFile("qa_data/json/sample2.json") if (llSuccess <> .T.) then ? loJson.LastErrorText release loJson return endif // First navigate to the "sampleData" object: loSampleData = loJson.ObjectOf("sampleData") // Demonstrate BoolAt and BoolOf ? "hungry: " + str(loSampleData.BoolOf("hungry")) ? "hungry: " + str(loSampleData.BoolAt(2)) // StringOf returns the value as a string regardless of it's actual type: ? "pi: " + loSampleData.StringOf("pi") ? "answer: " + loSampleData.StringOf("answer") ? "withoutValue: " + loSampleData.StringOf("withoutValue") ? "hungry: " + loSampleData.StringOf("hungry") // Demonstrate IsNullOf / IsNullAt ? "withoutValue is null? " + str(loSampleData.IsNullOf("withoutValue")) ? "withoutValue is null? " + str(loSampleData.IsNullAt(3)) ? "apple is null? " + str(loSampleData.IsNullOf("apple")) ? "apple is null? " + str(loSampleData.IsNullAt(1)) // IntOf ? "answer: " + str(loSampleData.IntOf("answer")) // SetNullAt, SetNullOf // Set "pi" to null llSuccess = loSampleData.SetNullAt(0) // Set "answer" to null llSuccess = loSampleData.SetNullOf("answer") // Show the changes: ? loJson.Emit() // Restore pi and apple: llSuccess = loSampleData.SetNumberAt(0,"3.14") llSuccess = loSampleData.SetNumberOf("answer","42") // Show the changes: ? loJson.Emit() // Add a null value named "afterApple" just after "apple" llSuccess = loSampleData.AddNullAt(2,"afterApple") // Add a boolean value just after "pi" llSuccess = loSampleData.AddBoolAt(1,"afterPi",.F.) release loSampleData // Examine the changes.. ? loJson.Emit() release loJson |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.