Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL cJsonArrayStr
LOCAL oSbJson
LOCAL oJson
LOCAL oJArray
LOCAL oJObjId

nSuccess := 0

//  Imagine we want to load this JSON array for parsing:
cJsonArrayStr := '[{"id":200},{"id":196}]'

//  First wrap it in a JSON object by prepending "{ "array":" and appending "}"
oSbJson := CreateObject("Chilkat.StringBuilder")
oSbJson:Append('{"array":')
oSbJson:Append(cJsonArrayStr)
oSbJson:Append("}")

oJson := CreateObject("Chilkat.JsonObject")
oJson:Load(oSbJson:GetAsString())

//  Now we can get the JSON array
oJArray := oJson:ArrayAt(0)

//  Do what you want with the JSON array...
//  For example:
oJObjId := oJArray:ObjectAt(0)
? Str(oJObjId:IntOf("id"))
oJObjId:destroy()

oJArray:destroy()

oSbJson:destroy()
oJson:destroy()