MyChat Scripts Engine: JSONGetInteger, get an integer from a JSON object
Function to obtain an integer value of a key from a JSON object.
Syntax
function JSONGetInteger(sJSON, sKey: string; var iValue: integer): integer;
Parameters and return values
Parameter |
Type |
Value |
sJSON |
string |
JSON object as a text string; |
sKey |
string |
required key name; |
iValue |
var integer |
key value, if available. |
Function result
0 |
no errors; |
1 |
JSON parsing error; |
2 |
key not found. |
Example
var
s: string;
iPrice: integer;
begin
s := '{"Apple" : 2, "Peach" : 6}';
if JSONGetInteger(s, 'Apple', iPrice) = 0 then
mLogScript('Apple''s price is: ' + inttostr(iPrice) + ' dollars.', 'TEST')
else mLogScript('Key not found or parsing error', 'TEST');
end.
Script work result
[21:27:36] (Log "test"): [TEST] Apple's price is: 2 dollars.