MyChat Scripts: JSONArrayGetDouble, get the fractional number from JSON array
"For developers", "Server scripts", "Functions description", "JSON", JSONArrayGetDouble.
Get the fractional number from JSON array by index. The numeration begins with 0.
Syntax
function JSONArrayGetDouble(sJSON: string; iIdx: integer; var iValue: double): integer;
Prameters and return values
Parameter |
Type |
Value |
sJSON |
string |
JSON object in a text form; |
iIdx |
integer |
index of the array element; |
var iValue |
double |
the content of the array element. |
Function result
-1 |
JSON parsing error; |
-2 |
incorrect index or array element type; |
0 |
function done successfully. |
Example
const
COUNT = 5;
var
sJSON: string;
i: integer;
dt: double;
begin
JSONArraySetLength(sJSON, COUNT);
for i := 1 to COUNT do JSONArraySetDouble(sJSON, i - 1, IncMonth(Now, i));
mLogScript(sJSON, '');
for i := 1 to COUNT do begin
JSONArrayGetDouble(sJSON, i - 1, dt);
mLogScript(FormatDateTime('mmm', dt), IntToStr(i));
end;
end.
Script work result
[16:35:07] (Log "JSONArrayGetDouble"): [43777.6910638194,43807.6910638194,43838.6910638194,43869.6910638194,43898.6910638194]
[16:35:07] (Log "JSONArrayGetDouble"): [1] nov
[16:35:07] (Log "JSONArrayGetDouble"): [2] dec
[16:35:07] (Log "JSONArrayGetDouble"): [3] jan
[16:35:07] (Log "JSONArrayGetDouble"): [4] feb
[16:35:07] (Log "JSONArrayGetDouble"): [5] mar
[16:35:07] (Run "JSONArrayGetDouble"): Script operation time: 4 ms
[16:35:07] (Run "JSONArrayGetDouble"): Script done successfully.