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
(PureBasic) 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.
IncludeFile "CkStringBuilder.pb" IncludeFile "CkJsonObject.pb" IncludeFile "CkJsonArray.pb" Procedure ChilkatExample() success.i ; Imagine we want to load this JSON array for parsing: jsonArrayStr.s = "[{" + Chr(34) + "id" + Chr(34) + ":200},{" + Chr(34) + "id" + Chr(34) + ":196}]" ; First wrap it in a JSON object by prepending "{ "array":" and appending "}" sbJson.i = CkStringBuilder::ckCreate() If sbJson.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkStringBuilder::ckAppend(sbJson,"{" + Chr(34) + "array" + Chr(34) + ":") CkStringBuilder::ckAppend(sbJson,jsonArrayStr) CkStringBuilder::ckAppend(sbJson,"}") json.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckLoad(json,CkStringBuilder::ckGetAsString(sbJson)) ; Now we can get the JSON array jArray.i = CkJsonObject::ckArrayAt(json,0) ; Do what you want with the JSON array... ; For example: jObjId.i = CkJsonArray::ckObjectAt(jArray,0) Debug Str(CkJsonObject::ckIntOf(jObjId,"id")) CkJsonObject::ckDispose(jObjId) CkJsonArray::ckDispose(jArray) CkStringBuilder::ckDispose(sbJson) CkJsonObject::ckDispose(json) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.