DataFlex
DataFlex
Load a JSON Array
See more JSON Examples
The 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.Chilkat DataFlex Downloads
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
Move False To iSuccess
// 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