This procedure converts JSON value to string. All escaped charactes are changed to binary representation in UCS format. Following conversion is applied:
Conversion
NOTE:Enough output memory must be allocated by caller.
Parameter | Type | Description | |
---|---|---|---|
inText_ptr | POINTER | Mandatory | Pointer to variable which contains character value in JSON coding (text which needs to be converted) |
inText_size | 10U 0 | Mandatory | Length of text in bytes |
outText_ptr | POINTER | Mandatory | Pointer to output text produced by procedure |
outText_size | 10U 0 | Mandatory | Input/output parameter. As an input the maximum size of allocated memory for output must be provided (in bytes). As output, procedure returns curent length of UCS2 text generated by conversion (In bytes). |
NOTE: Procedure operates on UCS2 input and output strings!
- Procedure returns *ON if everything is OK.
- Procedure returns *OFF in case of errors in conversion
Example:
D lString S 200C VARYING
D lStringTo S 16384C
D lStringToSize S 10U 0
lString = %UCS2('Sample text to change with \n');
lStringTo = *BLANKS;
lStringToSize = %Size(lStringTo);
if ucs2JsonValue( %addr(lString) + 2
:%len(lString) * 2
:%addr(lStringTo)
:lStringToSize);
lString = lStringTo;
%len(lString) = %DIV(lStringToSize : 2);
endif;
In the sample code above the value which must be converted was put into VARYING variable. This type of veriable contains length of text stored as first two bytes. That is why when variable pointer is passed to jsonValue2ucs() procedure the address is calculated as %addr(lString) + 2. Then then length in bytes of input text is calculated as %len(lString) * 2 as lString variable is defined as UCS2. The output text can be longer because of conversion, that is why the lStringTo was defined as 16384C variable. To move result back into lString variable two lines of code are required. First just put everything from lStringTo into lString. The second one sets length lString to correct value. Function %div() divides size of output by two to convert lengt in bytes to length in characters.