Table of Contents
Navigation: ABC Library Reference > JSON Data Class >JSONDataClass | |
This section covers commonly used methods/functions, the full class is installed in your Clarion\Libsrc\Win folder in the file JSON.INC and JSON.CLW
Usage
Declare an instance of the class in the data section of your Procedure, as in:
JSON JSONDataClass
Commonly used methods and Properties
ToJSON PROCEDURE(*GROUP pJSONObject),STRING
ToJSON PROCEDURE(*QUEUE pJSONArray),STRING
ToJSON PROCEDURE(STRING pJSONArrayName, *QUEUE pJSONArray),STRING
ToJSON PROCEDURE(*QUEUE pJSONArray,LONG pStartRecord, LONG pEndRecord),STRING
ToJSON PROCEDURE(STRING pJSONArrayName, *QUEUE pJSONArray,LONG pStartRecord, LONG pEndRecord),STRING
ToJSON PROCEDURE(*BYTE[] values),STRING
ToJSON PROCEDURE(*LONG[] values),STRING
ToJSON PROCEDURE(*STRING[] values),STRING
The ToJSON overloaded method(s) can accept a RECORD, GROUP, QUEUE, or an array of integers or strings.
ToJSON PROCEDURE(*GROUP pJSONObject),STRING
Receives a the LABEL of a GROUP (or RECORD) and RETURNS a STRING in name/key pair JSON format.
Example:
Product GROUP,PRE(Prod)
Name STRING(20)
Price decimal(12,2)
Quantity LONG
END
JSONString STRING(256)
CODE
Prod:Name = 'Widget'
Prod:Price = 45.99
Prod:Quantity = 12
CODE
JSONString = JSON.ToJSON(Product)
JSONString now has the value: {“PROD:NAME:: “Widget”, “PROD:PRICE”: 45.99, ”PROD:QUANTITY“: 12}
ToJSON PROCEDURE(*QUEUE pJSONArray),STRING
Receives a the LABEL of a QUEUE and RETURNS a STRING in name/key pair JSON format containing all records in the QUEUE.
Example:
Products QUEUE
Name STRING(20)
Price DECIMAL(12,2)
END
JSONString STRING(256)
CODE
Products.Name = 'Widget'
Products.Price = 45.99
ADD(Products)
Products.Name = 'Cool Gadget'
Products.Price = 5.99
ADD(Products)
JSONString = JSON.ToJSON(Products)
JSONString now has the value: [{“NAME:: “Widget”, “PRICE”: 45.99}, {“NAME:: “Cool Gadget”, “PRICE”: 5.99}]
FromJSON PROCEDURE(*STRING pJSONString,*GROUP pJSONObject)
FromJSON PROCEDURE(*STRING pJSONString,*QUEUE pJSONArray)
FromJSON PROCEDURE(*STRING pJSONString,*QUEUE pJSONArray, STRING pPicture)
JSON object
JSON Object
ClearObject PROCEDURE()
ClearObjectArray PROCEDURE()
GetObjectIsArray PROCEDURE(),BYTE
ClearObject PROCEDURE(*JSONDataValueQueue jsonQueue),PROTECTED
GetGroupSize PROCEDURE(*GROUP jsonGroup), LONG
GetGroupMaxSize PROCEDURE(*GROUP jsonGroup), LONG
GetJSONObjectSize PROCEDURE(), LONG, PROTECTED
ToJSON PROCEDURE(),STRING
AddString PROCEDURE(STRING name, STRING value)
AddBool PROCEDURE(STRING name, BYTE value)
AddNumber PROCEDURE(STRING name, LONG value)
AddNumber PROCEDURE(STRING name, LONG value, STRING picture)
AddGroup PROCEDURE(STRING name, *GROUP value)
AddQueue PROCEDURE(STRING name, *QUEUE value)
AddGroup PROCEDURE(*GROUP value)
Properties
SetClipValues PROCEDURE(BYTE value)
Property that determines whether STRING values are automatically clipped. Default is True.
GetClipValues PROCEDURE(),BYTE
Returns the current setting (True or False) for the SetClipValues property.
SetEscapeString PROCEDURE(BYTE value)
Property that determines whether STRING values are automatically escaped when they contain the following characters; quotation marks, forward slash or back slash, backspace, formfeed, newline, carriage returns, horizontal tab, 4 hexadecimal digits. Default is True.
GetEscapeString PROCEDURE(),BYTE
Returns the current setting (True or False) for the SetEscapeString property.
EscapeString PROCEDURE(STRING value),STRING
Receives a STRING parameter and applies escaping (the JSON escape character is the back slash \) when the STRING parameter contains any of the following characters; quotation marks, forward slash or back slash, backspace, formfeed, newline, carriage returns, horizontal tab, 4 hexadecimal digits. Returns a string with any special characters properly escaped for JSON.
UnEscapeString PROCEDURE(STRING value),STRING
Receives a JSON formatted string and removes all escape character(s) (JSON uses the back slash \ to escape special characters) and RETURNs the un-escaped string.
SetNumberformatter PROCEDURE(STRING fieldName, STRING picture)
Receives the LABEL of a variable and a PICTURE. This association of LABEL<;→PICTURE is used by the class to FORMAT and DEFORMAT fields when reading JSON data.
There are three special pseudo-pictures that you can use here:
@NULL will return 'null' when the value is an empty string as in ''
@BOOL will return 'true' or false '
@STRING will return a numeric value enclosed in double quotes (normally numeric values are not enclosed in quotation marks)
GetNumberformatter PROCEDURE(STRING fieldName),STRING
Returns the PICTURE associated with the fieldName parameter, if there is no PICTURE associated with the fieldName it RETURNs an empty string.
DeleteNumberformatter PROCEDURE(STRING fieldName)
Removes the fieldName from the Class's formatter Queue.