diff options
author | Christian Hesse <mail@eworm.de> | 2023-10-18 18:25:33 +0200 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2023-10-19 08:42:29 +0200 |
commit | 9138c17f8c3bbd415a0defe6ada431075a7c8f04 (patch) | |
tree | 1bc6962b33eb8f0298c5b01049ef3bab8b8a9cf4 | |
parent | fffe0a3b502fa43c3b836264bd1a7ca63f5b8aaa (diff) |
global-functions: $ParseJson: return array as ... array 😜
No need to assemble the string here, just to split it again later.
-rw-r--r-- | global-functions.rsc | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/global-functions.rsc b/global-functions.rsc index 878e95e..443771d 100644 --- a/global-functions.rsc +++ b/global-functions.rsc @@ -719,26 +719,33 @@ :local Val1 ($Input->($I + 1)); :local Val2 ($Input->($I + 2)); :if ($Val1 = ":") do={ - :set ($Return->$Key) $Val2; :set Skip 2; + :set ($Return->$Key) $Val2; :set Done true; } :if ($Done = false && $Val1 = ":[") do={ - :local Tmp ""; - :local End; + :local Last false; :set Skip 1; + :set ($Return->$Key) ({}); :do { :set Skip ($Skip + 1); :local ValX ($Input->($I + $Skip)); - :set End [ :pick $ValX ([ :len $ValX ] - 1) ]; - :set Tmp ($Tmp . "},{" . $ValX); - } while=($End != "]"); - :set ($Return->$Key) ("{" . [ :pick $Tmp 0 ([ :len $Tmp ] - 1) ] . "}"); + :if ([ :pick $ValX ([ :len $ValX ] - 1) ] = "]") do={ + :set Last true; + :set ValX [ :pick $ValX 0 ([ :len $ValX ] - 1) ]; + } + :set ($Return->$Key) (($Return->$Key), $ValX); + } while=($Last = false); + :set Done true; + } + :if ($Done = false && $Val1 = ":[]") do={ + :set Skip 1; + :set ($Return->$Key) ({}); :set Done true; } :if ($Done = false) do={ - :set ($Return->$Key) [ :pick $Val1 1 [ :len $Val1 ] ]; :set Skip 1; + :set ($Return->$Key) [ :pick $Val1 1 [ :len $Val1 ] ]; } } } |