![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PowerBuilder) JSON: Nested ObjectsHere we have a JSON object that contains nested JSON objects. This example demonstrates how to access the contents of the nested objects. { "name": "donut", "image": { "fname": "donut.jpg", "w": 200, "h": 200 }, "thumbnail": { "fname": "donutThumb.jpg", "w": 32, "h": 32 } } Note: This example requires Chilkat v11.0.0 or greater.
integer li_rc integer li_Success oleobject loo_Json string ls_JsonStr oleobject loo_ImageObj oleobject loo_ThumbObj li_Success = 0 loo_Json = create oleobject li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject") if li_rc < 0 then destroy loo_Json MessageBox("Error","Connecting to COM object failed") return end if // This is the above JSON with whitespace chars removed (SPACE, TAB, CR, and LF chars). // The presence of whitespace chars for pretty-printing makes no difference to the Load // method. ls_JsonStr = "{~"name~": ~"donut~",~"image~":{~"fname~": ~"donut.jpg~",~"w~": 200,~"h~": 200},~"thumbnail~":{~"fname~": ~"donutThumb.jpg~",~"w~": 32,~"h~": 32}}" li_Success = loo_Json.Load(ls_JsonStr) if li_Success = 0 then Write-Debug loo_Json.LastErrorText destroy loo_Json return end if // Get the "image" object. loo_ImageObj = create oleobject li_rc = loo_ImageObj.ConnectToNewObject("Chilkat.JsonObject") loo_Json.ObjectOf2("image",loo_ImageObj) Write-Debug "image: fname=" + loo_ImageObj.StringOf("fname") + ", width=" + string(loo_ImageObj.IntOf("w")) + ", height=" + string(loo_ImageObj.IntOf("h")) // Get the "thumbnail" object. loo_ThumbObj = create oleobject li_rc = loo_ThumbObj.ConnectToNewObject("Chilkat.JsonObject") loo_Json.ObjectOf2("thumbnail",loo_ThumbObj) Write-Debug "thumbnail: fname=" + loo_ThumbObj.StringOf("fname") + ", width=" + string(loo_ThumbObj.IntOf("w")) + ", height=" + string(loo_ThumbObj.IntOf("h")) destroy loo_Json destroy loo_ImageObj destroy loo_ThumbObj |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.