mirror of
https://github.com/eworm-de/routeros-scripts
synced 2024-05-14 08:04:19 +00:00
global-functions: make $ParseJson global
This commit is contained in:
parent
8e9734347e
commit
080b3cbf9d
2 changed files with 30 additions and 26 deletions
|
@ -48,6 +48,7 @@
|
|||
:global MkDir;
|
||||
:global NotificationFunctions;
|
||||
:global ParseDate;
|
||||
:global ParseJson;
|
||||
:global ParseKeyValueStore;
|
||||
:global PrettyPrint;
|
||||
:global RandomDelay;
|
||||
|
@ -694,6 +695,34 @@
|
|||
"day"=[ :tonum [ :pick $Date 8 10 ] ] });
|
||||
}
|
||||
|
||||
# parse JSON into array
|
||||
# Warning: This is not a complete parser!
|
||||
:set ParseJson do={
|
||||
:local Input [ :toarray $1 ];
|
||||
|
||||
:local Return ({});
|
||||
:local Skip 0;
|
||||
|
||||
:for I from=0 to=([ :len $Input ] - 1) do={
|
||||
:if ($Skip > 0 || $Input->$I = "\n" || $Input->$I = "\r\n") do={
|
||||
:if ($Skip > 0) do={
|
||||
:set $Skip ($Skip - 1);
|
||||
}
|
||||
} else={
|
||||
:local Key ($Input->$I);
|
||||
:if ($Input->($I + 1) = ":") do={
|
||||
:set ($Return->$Key) ($Input->($I + 2));
|
||||
:set Skip 2;
|
||||
} else={
|
||||
:set ($Return->$Key) [ :pick ($Input->($I + 1)) 1 [ :len ($Input->($I + 1)) ] ];
|
||||
:set Skip 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:return $Return;
|
||||
}
|
||||
|
||||
# parse key value store
|
||||
:set ParseKeyValueStore do={
|
||||
:local Source $1;
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
:global IfThenElse;
|
||||
:global LogPrintExit2;
|
||||
:global MkDir;
|
||||
:global ParseJson;
|
||||
:global ScriptLock;
|
||||
:global SendTelegram2;
|
||||
:global SymbolForNotification;
|
||||
|
@ -45,32 +46,6 @@ $WaitFullyConnected;
|
|||
$LogPrintExit2 warning $0 ("Downloading required certificate failed.") true;
|
||||
}
|
||||
|
||||
:local ParseJson do={
|
||||
:local Input [ :toarray $1 ];
|
||||
|
||||
:local Return ({});
|
||||
:local Skip 0;
|
||||
|
||||
:for I from=0 to=([ :len $Input ] - 1) do={
|
||||
:if ($Skip > 0 || $Input->$I = "\n" || $Input->$I = "\r\n") do={
|
||||
:if ($Skip > 0) do={
|
||||
:set $Skip ($Skip - 1);
|
||||
}
|
||||
} else={
|
||||
:local Key ($Input->$I);
|
||||
:if ($Input->($I + 1) = ":") do={
|
||||
:set ($Return->$Key) ($Input->($I + 2));
|
||||
:set Skip 2;
|
||||
} else={
|
||||
:set ($Return->$Key) [ :pick ($Input->($I + 1)) 1 [ :len ($Input->($I + 1)) ] ];
|
||||
:set Skip 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
:return $Return;
|
||||
}
|
||||
|
||||
:local Data;
|
||||
:do {
|
||||
:set Data ([ /tool/fetch check-certificate=yes-without-crl output=user \
|
||||
|
|
Loading…
Reference in a new issue