MyChat Scripts Engine: JSONArrayGetString, get a string from a JSON array
Function to obtain a specified text element from a JSON array by index. The array index begins from 0.
Syntax
function JSONArrayGetString(sJSON: string; iIdx: integer; var sValue: string): 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 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
const
JSON = '["Hello, darkness, my old friend.",' +
'"I''ve come to talk with you again",' +
'"Because a vision softly creeping,",' +
'"Left its seeds while I was sleeping."]';
var
iCount, i: integer;
s: string;
begin
iCount := JSONArrayLength(JSON);
if iCount > 0 then
for i := 0 to iCount - 1 do
if JSONArrayGetString(JSON, i, s) = 0 then
mLogScript(s, '');
end.
Script work result
[11:04:26] (Log "JSONArrayGetString"): Hello, darkness, my old friend.
[11:04:26] (Log "JSONArrayGetString"): I've come to talk with you again
[11:04:26] (Log "JSONArrayGetString"): Because a vision softly creeping,
[11:04:26] (Log "JSONArrayGetString"): Left its seeds while I was sleeping.
[11:04:26] (Run "JSONArrayGetString"): Script operation time: 6 ms
[11:04:26] (Run "JSONArrayGetString"): Script done successfully.
See also
Created with the Personal Edition of HelpNDoc: Bring your WinHelp HLP help files into the present with HelpNDoc's easy CHM conversion