MyChat Scripts Engine: JSONArrayGetDateTime, get the det/time from a JSON array
Function to obtain the date/time value from a JSON array by index. Numeration begins from 0.
Syntax
function JSONArrayGetDateTime(sJSON: string; iIdx: integer; var dtValue: double): integer;
Parameters and return values
Parameter |
Type |
Value |
sJSON |
string |
JSON object as a text string; |
iIdx |
integer |
index of the required array element; |
var dtValue |
double |
contents of the array element. |
Function result
-1 |
JSON parsing problem; |
-2 |
invalid index or type of the array element; |
0 |
function done successfully. |
Example
const
JSONDATES = '["09.07.1812", "09.01.1939", "04.12.1961"]';
JSONEVENTS = '["Borodino battle", "World War II", "The first orbital spaceflight"]';
var
iCount, i: integer;
dt: double;
sName: string;
begin
iCount := JSONArrayLength(JSONDATES);
if iCount > 0 then
for i := 0 to iCount - 1 do begin
JSONArrayGetDateTime(JSONDATES, i, dt);
JSONArrayGetString(JSONEVENTS, i, sName);
mLogScript(sName, FormatDateTime('mmm d yyyy', dt));
end;
end.
Script work result
[13:24:22] (Log "JSONGetArrayDateTime"): [sep 7 1812] Borodino battle
[13:24:22] (Log "JSONGetArrayDateTime"): [sep 1 1939] World War II
[13:24:22] (Log "JSONGetArrayDateTime"): [apr 12 1961] The first orbital spaceflight
[13:24:22] (Run "JSONGetArrayDateTime"): Script operation time: 6 ms
[13:24:22] (Run "JSONGetArrayDateTime"): Script done successfully.