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
(DataFlex) Load a JSON ArrayThe Chilkat JSON API requires the top-level JSON to be an object. Therefore, to load an array requires that it first be wrapped as an object.
Use ChilkatAx-win32.pkg Procedure Test Boolean iSuccess String sJsonArrayStr Handle hoSbJson Handle hoJson Variant vJArray Handle hoJArray Variant vJObjId Handle hoJObjId String sTemp1 Integer iTemp1 // Imagine we want to load this JSON array for parsing: Move '[{"id":200},{"id":196}]' To sJsonArrayStr // First wrap it in a JSON object by prepending "{ "array":" and appending "}" Get Create (RefClass(cComChilkatStringBuilder)) To hoSbJson If (Not(IsComObjectCreated(hoSbJson))) Begin Send CreateComObject of hoSbJson End Get ComAppend Of hoSbJson '{"array":' To iSuccess Get ComAppend Of hoSbJson sJsonArrayStr To iSuccess Get ComAppend Of hoSbJson "}" To iSuccess Get Create (RefClass(cComChilkatJsonObject)) To hoJson If (Not(IsComObjectCreated(hoJson))) Begin Send CreateComObject of hoJson End Get ComGetAsString Of hoSbJson To sTemp1 Get ComLoad Of hoJson sTemp1 To iSuccess // Now we can get the JSON array Get ComArrayAt Of hoJson 0 To vJArray If (IsComObject(vJArray)) Begin Get Create (RefClass(cComChilkatJsonArray)) To hoJArray Set pvComObject Of hoJArray To vJArray End // Do what you want with the JSON array... // For example: Get ComObjectAt Of hoJArray 0 To vJObjId If (IsComObject(vJObjId)) Begin Get Create (RefClass(cComChilkatJsonObject)) To hoJObjId Set pvComObject Of hoJObjId To vJObjId End Get ComIntOf Of hoJObjId "id" To iTemp1 Showln iTemp1 Send Destroy of hoJObjId Send Destroy of hoJArray End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.