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
(AutoIt) 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 } }
$oJson = ObjCreate("Chilkat.JsonObject") $oJson.EmitCompact = False ; Assume the file contains the data as shown above.. Local $bSuccess = $oJson.LoadFile("qa_data/json/sample2.json") If ($bSuccess <> True) Then ConsoleWrite($oJson.LastErrorText & @CRLF) Exit EndIf ; First navigate to the "sampleData" object: Local $oSampleData = $oJson.ObjectOf("sampleData") ; Demonstrate BoolAt and BoolOf ConsoleWrite("hungry: " & $oSampleData.BoolOf("hungry") & @CRLF) ConsoleWrite("hungry: " & $oSampleData.BoolAt(2) & @CRLF) ; StringOf returns the value as a string regardless of it's actual type: ConsoleWrite("pi: " & $oSampleData.StringOf("pi") & @CRLF) ConsoleWrite("answer: " & $oSampleData.StringOf("answer") & @CRLF) ConsoleWrite("withoutValue: " & $oSampleData.StringOf("withoutValue") & @CRLF) ConsoleWrite("hungry: " & $oSampleData.StringOf("hungry") & @CRLF) ; Demonstrate IsNullOf / IsNullAt ConsoleWrite("withoutValue is null? " & $oSampleData.IsNullOf("withoutValue") & @CRLF) ConsoleWrite("withoutValue is null? " & $oSampleData.IsNullAt(3) & @CRLF) ConsoleWrite("apple is null? " & $oSampleData.IsNullOf("apple") & @CRLF) ConsoleWrite("apple is null? " & $oSampleData.IsNullAt(1) & @CRLF) ; IntOf ConsoleWrite("answer: " & $oSampleData.IntOf("answer") & @CRLF) ; SetNullAt, SetNullOf ; Set "pi" to null $bSuccess = $oSampleData.SetNullAt(0) ; Set "answer" to null $bSuccess = $oSampleData.SetNullOf("answer") ; Show the changes: ConsoleWrite($oJson.Emit() & @CRLF) ; Restore pi and apple: $bSuccess = $oSampleData.SetNumberAt(0,"3.14") $bSuccess = $oSampleData.SetNumberOf("answer","42") ; Show the changes: ConsoleWrite($oJson.Emit() & @CRLF) ; Add a null value named "afterApple" just after "apple" $bSuccess = $oSampleData.AddNullAt(2,"afterApple") ; Add a boolean value just after "pi" $bSuccess = $oSampleData.AddBoolAt(1,"afterPi",False) ; Examine the changes.. ConsoleWrite($oJson.Emit() & @CRLF) |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.