Sample code for 30+ languages & platforms
Visual Basic 6.0

JSON Iterate Members

See more JSON Examples

Demonstrates how to loop over the immediate members of a JSON object.

Chilkat Visual Basic 6.0 Downloads

Visual Basic 6.0
Dim success As Long
success = 0

Dim json As New ChilkatJsonObject

Dim jsonStr As String
jsonStr = "{ ""id"": 1, ""name"": ""A green door"", ""tags"": [""home"", ""green""], ""price"": 125 }"

success = json.Load(jsonStr)
If (success <> 1) Then
    Debug.Print json.LastErrorText
    Exit Sub
End If

Dim numMembers As Long
numMembers = json.Size
Dim i As Long
For i = 0 To numMembers - 1

    Dim name As String
    name = json.NameAt(i)
    Dim value As String
    value = json.StringAt(i)

    Debug.Print name & ": " & value

    Dim iValue As Long
    iValue = json.IntAt(i)
    Debug.Print name & " as integer: " & iValue

Next

' Note: The StringAt method returns the value as a string regardless of the type.
' If the value is a JSON array (such as for ["home", "green"]), then the JSON encoding
' of the entire array is returned.

' The IntAt method returns the value as an integer.  If the value does not convert to 
' an integer, then 0 is returned