Parameter | Description |
---|---|
data | Data to convert to JSON |
Procedure DataTypeToJson Struct data
Call: | Send DataTypeToJson data |
Converts a native DataFlex variable (usually a struct / array) into a JSON object structure representing that data.
This can be used to serialize struct data into a JSON string, where DataTypeToJson would be followed by a Stringify call returning the actual string.
The Name meta-data tag allows you to designate an alternate name to Struct members that is used when serializing and deserializing structs to and from JSON and XML.
This sample code shows how to give an external name of "Number" to a struct member that is a reserved word in DataFlex.
Struct tMyStruct Integer iItemId { Name="Number" } Integer iQuantity End_Struct Function GenerateJson Returns String Handle hoJson tMyStruct data String sResult Get Create (RefClass(cJsonObject)) to hoJson Move 24 to data.iItemId Move 5 to data.iQuantity Send DataTypeToJson of hoJson data Set peWhiteSpace of hoJson to jpWhitespace_Spaced Get Stringify of hoJson to sResult Send Destroy of hoJson Function_Return sResult End_Function
Generates the following JSON:
{ "iItemId": 24, "Number": 5 }
Do not augment this message.