Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/svan-jansson/vdfwebtools
A set of web tools for Visual Dataflex
https://github.com/svan-jansson/vdfwebtools
Last synced: 8 days ago
JSON representation
A set of web tools for Visual Dataflex
- Host: GitHub
- URL: https://github.com/svan-jansson/vdfwebtools
- Owner: svan-jansson
- License: mit
- Created: 2013-04-06T09:00:59.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2021-03-22T00:37:47.000Z (almost 4 years ago)
- Last Synced: 2024-11-21T20:21:18.034Z (2 months ago)
- Size: 52.7 KB
- Stars: 2
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# VdfWebTools
This is a set of helper classes for working with web requests and web content in DataFlex.
## JSON Examples
### Table of Contents
1. [Context](#context)
2. [Parsing an Object](#parsing-object)
3. [Parsing an Array](#parsing-array)
3. [Creating and Serializing a JSON Object](#serializing-object)### Context
* The `cJSONParser` class helps you parse JSON strings using the `Parse` procedure.
* The `cJSONDictionary` class helps you access, mutate and serialize JSON objects. It depends on [cHashTable](https://github.com/svan-jansson/cHashTable) and [cRegex](https://github.com/svan-jansson/cRegex).### Parsing an Object
```dataflexProcedure ParsingExample
Handle hParser hDictionary
String sJSON sValue
Move '{"stringValue": "this is a string"}' to sJSON
Get Create U_cJSONParser to hParser
Get Create U_cJSONDictionary to hDictionary
Send Parse of hParser sJSON hDictionary
If (Found) Begin
Get Value of hDictionary "stringValue" to sValue // "this is a string"
End
Send Destroy of hParser
Send Destroy of hDictionary
End_Procedure```
```dataflex
Procedure ParsingExample
Handle hParser hDictionary
String sJSON sValue
Variant[] vaArray
Move '["first", "second", "third"]' to sJSONGet Create U_cJSONParser to hParser
Get Create U_cJSONDictionary to hDictionary
Send Parse of hParser sJSON hDictionaryIf (Found) Begin
Get Value of hDictionary "_array" to vaArray // "_array" is a pseudo element for top-level JSON arrays
Move vaArray[1] to sValue // "second"
End
Send Destroy of hParser
Send Destroy of hDictionary
End_Procedure
```### Creating and Serializing a JSON Object
Let's recreate this JSON string using DataFlex:
```json
{
"type": "Horse",
"properties": {
"legs": 4,
"hasStripes": false
},
"relatedAnimals": [
"Zebra",
"Mule"
]
}
``````dataflex
Procedure SerializingExample
Handle hAnimal hProperties
Variant[] vaRelatedAnimals
String sJSON
Move "Zebra" to vaRelatedAnimals[0]
Move "Mule" to vaRelatedAnimals[1]
Get Create U_cJSONDictionary to hAnimal
Get Create U_cJSONDictionary to hProperties
Set TypedValue of hAnimal "type" _jsond_string to "Horse"
Set TypedValue of hAnimal "properties" _jsond_object to hProperties
Set TypedValue of hAnimal "relatedAnimals" _jsond_array to vaRelatedAnimals
Set TypedValue of hProperties "legs" _jsond_number to 4
Set TypedValue of hProperties "hasStripes" _jsond_bool to false
Get Serialize of hAnimal to sJSON // { "type": "Horse", ... }
Send Destroy of hAnimal
Send Destroy of hProperties
End_Procedure
```