MyChat Scripts Engine: JSONArraySetBoolean, change the boolean value in a JSON array
Changing a specified Boolean element of a JSON array by index. The array index begins from 0.
Syntax
function JSONArraySetBoolean(var sJSON: string; iIdx: integer; bValue: boolean): integer;
Parameters and return values
Parameter |
Type |
Value |
var sJSON |
string |
JSON object as a text string; |
iIdx |
integer |
index of the required array element; |
bValue |
boolean |
array element content. |
Function result
-1 |
JSON parsing error; |
-2 |
invalid index or type of the array element; |
0 |
function done successfully. |
Example
var
JSONArr: string;
i, iCount: integer;
begin
JSONArr := '[]';
for i := 0 to 4 do JSONArraySetBoolean(JSONArr, i, false);
mLogScript(JSONArr, 'At start');
iCount := JSONArrayLength(JSONArr);
for i := 0 to iCount - 1 do
if (i mod 2) = 0 then JSONArraySetBoolean(JSONArr, i, true);
mLogScript(JSONArr, 'Final');
end.
Script work result
[14:10:06] (Log "JSONArraySetBoolean"): [At start] [false,false,false,false,false]
[14:10:06] (Log "JSONArraySetBoolean"): [Final] [true,false,true,false,true]
[14:10:06] (Run "JSONArraySetBoolean"): Script operation time: 6 ms
[14:10:06] (Run "JSONArraySetBoolean"): Script done successfully.