MyChat Scripts Engine: JSONArraySetString, change a string in a JSON array
Changing a specified text element of a JSON array by index. The index begins from 0.
Syntax
function JSONArraySetString(var sJSON: string; iIdx: integer; sValue: string): 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; |
sValue |
string |
the contents of the array element. |
Function result
-1 |
JSON parsing error; |
-2 |
invalid index or type of the array element; |
0 |
function done successfully. |
Example
var
JSONArr, s: string;
begin
JSONArr := '["first", "second", "third"]';
mLogScript(JSONArr, 'before');
JSONArrayGetString(JSONArr, 1, s);
JSONArraySetString(JSONArr, 1, UpperCase(s));
mLogScript(JSONArr, 'after');
end.
Script work result
[13:46:05] (Log "JSONArraySetString"): [before] ["first", "second", "third"]
[13:46:05] (Log "JSONArraySetString"): [after] ["first","SECOND","third"]
[13:46:05] (Run "JSONArraySetString"): Script operation time: 6 ms
[13:46:05] (Run "JSONArraySetString"): Script done successfully.