VBMAN JSON Data Processing Example
Overview
This example demonstrates how to process JSON data using the VBMAN framework, including JSON creation, parsing, modification, and serialization operations. VBMAN provides a simple and easy-to-use JSON API.
Project Structure
Json/
├── Form1.frm # Main form containing JSON operation example code
├── Form1.frx # Form resource file
└── VBMAN_DEMOS.vbp # VB6 project file
Core Code Analysis
1. JSON Object Creation and Property Setting
vb
With VBMAN.Json
.Item("a") = 1 'Set numeric type
.Item("b") = "dengwei" 'Set string type
'Create nested array
With .NewItems("c")
For i = 0 To 3
With .NewItem() 'Add array element
.Item("d") = Now()
.Item("e") = 34 + i
.Item("f") = "Test content: " & i
End With
Next
End With
End With
2. JSON File Operations
vb
'Save JSON to file
.SaveTo "c:\tmp\demo.json", , 2 'Third parameter is formatting indent spaces
'Load JSON from file
With VBMAN.Json.LoadFrom("c:\tmp\demo.json")
MsgBox .Root("b") 'Access top-level property
MsgBox .Root("c")(1)("f") 'Access nested property
End With
3. JSON Data Access
vb
'Using array index (starting from 1)
MsgBox json("c")(2)("f")
'Using For Each iteration
Dim x As Variant
For Each x In json("c")
Debug.Print x("f")
Next
'Using index iteration
For i = 1 To json("c").Count
Debug.Print json("c")(i)("f")
Next
4. JSON Serialization
vb
'Convert JSON to formatted string
Text1.Text = json.Encode(, 2, True)
'Parameters:
'2nd parameter: indent spaces
'3rd parameter: use Unicode
Feature Description
JSON Data Creation
- Support for various data types (numbers, strings, booleans, etc.)
- Support for nested objects and arrays
- Chainable API operations
- Automatic type conversion
JSON Data Access
- Access using keys or indices
- Support for multi-level nested access
- Support for array iteration
- Support for collection operations
JSON Serialization
- Formatted output
- Unicode support
- Custom indentation
- File I/O support
Technical Points
- Object-oriented JSON API design
- Support for complex nested data structures
- Complete file operation support
- Flexible iteration methods
- Formatted output control
Use Cases
- Web API data exchange
- Configuration file processing
- Data serialization
- Frontend-backend data communication
Extension Suggestions
- Add JSON Schema validation
- Add JSON Path querying
- Implement JSON data compression
- Add more helper functions
- Implement JSON data comparison functionality