Sv: O7:Format JASON-string
Daniel Sananes
daniel.s at kopparbergs.se
Thu Jan 7 17:17:30 UTC 2021
Thanks to all that responded.
I ended up calculating this myself.
Code below will give a JSON-format for a string like the one in my first mail below.
The indentation is all that is missing.
Regards
Daniel
; -----
; String to JSON-format
; -----
;
Calculate LTEXT as FRECIEVEFROMCURL
;
Repeat
Calculate LCOUNT as LCOUNT+1
Calculate LSIGN as pick(LCOUNT;0;'[';'{';',';'}';']')
Calculate %POS as pos(LSIGN;LTEXT)
If %POS>0
Calculate LBEGIN as mid(LTEXT;1;%POS)
Calculate LEND as mid(LTEXT;%POS+1;10000)
Calculate LTEXT as con(LBEGIN;LCHR13;LEND)
End If
Repeat
Calculate %POS as pos(LSIGN;LEND)
If %POS>0
Calculate LBEGIN as con(LBEGIN;LCHR13;mid(LEND;1;%POS))
Calculate LEND as mid(LEND;%POS+1;10000)
Calculate LTEXT as con(LBEGIN;LCHR13;LEND)
End If
Until %POS=0
Until LCOUNT=3
Repeat
Calculate LCOUNT as LCOUNT+1
Calculate LSIGN as pick(LCOUNT;0;'[';'{';',';'}';']')
Calculate %POS as pos(LSIGN;LTEXT)
If %POS>0
Calculate LBEGIN as con(mid(LTEXT;1;%POS-1);LCHR13;mid(LTEXT;%POS;1))
Calculate LEND as mid(LTEXT;%POS+1;10000)
Calculate LTEXT as con(LBEGIN;LCHR13;LEND)
End If
Repeat
Calculate %POS as pos(LSIGN;LEND)
If %POS>0
Calculate LBEGIN as con(LBEGIN;mid(LEND;1;%POS-1);LCHR13;mid(LEND;%POS;1))
Calculate LEND as mid(LEND;%POS+1;10000)
Calculate LTEXT as con(LBEGIN;LEND)
End If
Until %POS=0
Until LCOUNT=5
Calculate FRECIEVEFROMCURL as LTEXT (Redraw field)
;
Quit procedure
;
Local variable LTEXT (Character 10000000)
Local variable LSIGN (Character 1) = '['
Local variable LPOSINCR (Long integer) = 1
Local variable LBEGIN (Character 10000000)
Local variable LCHR13 (Character 10000000) = chr(13)
Local variable LEND (Character 10000000)
Local variable LCOUNT (Short integer (0 to 255))
-----Ursprungligt meddelande-----
Från: omnisdev-en <omnisdev-en-bounces at lists.omnis-dev.com> För Daniel Sananes
Skickat: den 6 januari 2021 20:50
Till: OmnisDev List - English <omnisdev-en at lists.omnis-dev.com>
Ämne: O7:Format JASON-string
Hallo
Is there some code or other tool that I could implement in Omnis 7 to format a JSON-string so it will be readable.
Below is a string received from an API-call:
[{"depo":{"srsId":"0002547061341"},"items":[{"number":"902","name":"Helpall Grå","types":[{"value":0,"name":"OK"}]},{"number":"901","name":"Helpall Svart","types":[{"value":0,"name":"OK"}]}]},{"depo":{"srsId":"0002547061358"},"items":[{"number":"901","name":"Helpall Svart","types":[{"value":0,"name":"OK"}]}]}]
I would like to extract the information and put the values into variables.
This JSON thing is new to me but I know it is a common subject here in our forum.
---
Best regards to everyone.
Daniel
_____________________________________________________________
Manage your list subscriptions at http://lists.omnis-dev.com Start a new message -> mailto:omnisdev-en at lists.omnis-dev.com
More information about the omnisdev-en
mailing list