PowerBuilder
PowerBuilder
Iterate over JSON Array containing JSON Objects
See more JSON Examples
Demonstrates how to load a JSON array and iterate over the JSON objects.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_SbJsonArray
oleobject loo_Arr
integer li_TagId
string ls_TagDescription
integer li_IsPublic
integer i
integer li_Count
oleobject loo_Obj
li_Success = 0
// Loads the following JSON array and iterates over the objects:
//
// [
// {"tagId":95,"tagDescription":"hola 1","isPublic":true},
// {"tagId":98,"tagDescription":"hola 1","isPublic":true},
// {"tagId":101,"tagDescription":"hola 1","isPublic":true},
// {"tagId":104,"tagDescription":"hola 1","isPublic":true},
// {"tagId":107,"tagDescription":"hola 1","isPublic":true},
// {"tagId":110,"tagDescription":"hola 1","isPublic":true},
// {"tagId":113,"tagDescription":"hola 1","isPublic":true},
// {"tagId":114,"tagDescription":"hola 2","isPublic":true},
// {"tagId":111,"tagDescription":"hola 2","isPublic":true},
// {"tagId":108,"tagDescription":"hola 2","isPublic":true},
// {"tagId":105,"tagDescription":"hola 2","isPublic":true},
// {"tagId":102,"tagDescription":"hola 2","isPublic":true},
// {"tagId":99,"tagDescription":"hola 2","isPublic":true},
// {"tagId":96,"tagDescription":"hola 2","isPublic":true},
// {"tagId":97,"tagDescription":"hola 3","isPublic":true},
// {"tagId":100,"tagDescription":"hola 3","isPublic":true},
// {"tagId":103,"tagDescription":"hola 3","isPublic":true},
// {"tagId":106,"tagDescription":"hola 3","isPublic":true},
// {"tagId":109,"tagDescription":"hola 3","isPublic":true},
// {"tagId":112,"tagDescription":"hola 3","isPublic":true},
// {"tagId":115,"tagDescription":"hola 3","isPublic":true},
// {"tagId":93,"tagDescription":"new tag","isPublic":true},
// {"tagId":94,"tagDescription":"new tag","isPublic":true},
// {"tagId":89,"tagDescription":"tag 1","isPublic":true},
// {"tagId":90,"tagDescription":"tag 2","isPublic":true},
// {"tagId":91,"tagDescription":"tag private 1","isPublic":false},
// {"tagId":92,"tagDescription":"tag private 2","isPublic":false}
// ]
// Load a file containing the above JSON..
loo_SbJsonArray = create oleobject
li_rc = loo_SbJsonArray.ConnectToNewObject("Chilkat.StringBuilder")
if li_rc < 0 then
destroy loo_SbJsonArray
MessageBox("Error","Connecting to COM object failed")
return
end if
li_Success = loo_SbJsonArray.LoadFile("qa_data/json/arraySample.json","utf-8")
loo_Arr = create oleobject
li_rc = loo_Arr.ConnectToNewObject("Chilkat.JsonArray")
li_Success = loo_Arr.LoadSb(loo_SbJsonArray)
i = 0
li_Count = loo_Arr.Size
do while i < li_Count
loo_Obj = loo_Arr.ObjectAt(i)
li_TagId = loo_Obj.IntOf("tagId")
ls_TagDescription = loo_Obj.StringOf("tagDescription")
li_IsPublic = loo_Obj.BoolOf("isPublic")
Write-Debug "tagId: " + string(li_TagId)
Write-Debug "tagDescription: " + ls_TagDescription
Write-Debug "isPublic: " + string(li_IsPublic)
Write-Debug "--"
destroy loo_Obj
i = i + 1
loop
destroy loo_SbJsonArray
destroy loo_Arr