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
(Visual FoxPro) 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 } }
LOCAL loJson LOCAL lnSuccess LOCAL loSampleData * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject') loJson = CreateObject('Chilkat.JsonObject') loJson.EmitCompact = 0 * Assume the file contains the data as shown above.. lnSuccess = loJson.LoadFile("qa_data/json/sample2.json") IF (lnSuccess <> 1) THEN ? loJson.LastErrorText RELEASE loJson CANCEL 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 lnSuccess = loSampleData.SetNullAt(0) * Set "answer" to null lnSuccess = loSampleData.SetNullOf("answer") * Show the changes: ? loJson.Emit() * Restore pi and apple: lnSuccess = loSampleData.SetNumberAt(0,"3.14") lnSuccess = loSampleData.SetNumberOf("answer","42") * Show the changes: ? loJson.Emit() * Add a null value named "afterApple" just after "apple" lnSuccess = loSampleData.AddNullAt(2,"afterApple") * Add a boolean value just after "pi" lnSuccess = loSampleData.AddBoolAt(1,"afterPi",0) RELEASE loSampleData * Examine the changes.. ? loJson.Emit() RELEASE loJson |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.