Create JSON from struct: Difference between revisions
From DataFlex Wiki
Jump to navigationJump to search
Created page with "Sometimes you have data as a DataFlex struct, but need it in JSON format. The code below gives an example on how-to change your data format so that it is available as JSON. Ha..." |
m Send not get |
||
(4 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
The code below gives an example on how-to change your data format so that it is available as JSON. | The code below gives an example on how-to change your data format so that it is available as JSON. | ||
<source lang="dataflex"> | |||
Handle hoJson | Handle hoJson | ||
UChar[] ucaJson | UChar[] ucaJson | ||
Line 9: | Line 10: | ||
Get Create (RefClass(cJsonObject)) to hoJson | Get Create (RefClass(cJsonObject)) to hoJson | ||
Send DataTypeToJson of hoJson tYourStructVar | |||
Get StringifyUTF8 of hoJson to ucaJson | Get StringifyUTF8 of hoJson to ucaJson | ||
Get Seq_New_Channel to iChn | Get Seq_New_Channel to iChn | ||
Line 16: | Line 17: | ||
Close_Output | Close_Output | ||
Send Seq_Release_Channel iChn | Send Seq_Release_Channel iChn | ||
Send Destroy of hoJson | |||
</source> | |||
=== External Links === | === External Links === | ||
The above was written by Mike Peat and has been taken from the following forum post: | The above was written by Mike Peat and has been taken from the following forum post: | ||
* https://support.dataaccess.com/Forums/showthread.php?63071-YAFR-Create-RDS-report-based-on-Struct-definition(s)&p=336276#post336276 | |||
* [https://docs.dataaccess.com/dataflexhelp/mergedProjects/Tools/Name_Meta-Data_Tag.htm Name meta-data tag] | |||
[[Category: Tutorials]] | [[Category: Tutorials]] | ||
[[Category:JSON]] |
Latest revision as of 18:37, 30 October 2021
Sometimes you have data as a DataFlex struct, but need it in JSON format.
The code below gives an example on how-to change your data format so that it is available as JSON.
Handle hoJson UChar[] ucaJson Integer iChn tYourDataType tYourStructVar Get Create (RefClass(cJsonObject)) to hoJson Send DataTypeToJson of hoJson tYourStructVar Get StringifyUTF8 of hoJson to ucaJson Get Seq_New_Channel to iChn Direct_Output channel iChn {filename} Write channel iChn ucaJson Close_Output Send Seq_Release_Channel iChn Send Destroy of hoJson
External Links
The above was written by Mike Peat and has been taken from the following forum post: