$listorrowtojson & $jsontolistorrow

Bruno Del Sol bruno.delsol at bydesign.fr
Thu Apr 22 06:57:05 UTC 2021


Hi Mike,

I ran into this issue recently, and since I didn't want to use a full OJSON object to deal with it i came up with a 
quick and dirty workaround. The method below takes the list of rows returned by $jsontolistorrow (ie #L1 in your 
example) or by the pContents var in POST calls and fixes it.

(Thanks to you if you post an ER to your East coast comrades asking if they could have $jsontolistorrow to do that directly)


$listofrows2list
--------------------

# parameter json is a list (ie was a js array) with a single col which is 
a row (ie was a js object)
# returns a list

If not(json.$colcount=1)
Quit method #NULL ## not a list of rows
End If

Calculate row as json.1.C1

If row.$colcount=0
Quit method #NULL ## not a row
End If
Do returnlist.$copydefinition(row)

Calculate json.$line as 0
While json.$next(0)
Do returnlist.$add()
Calculate returnlist.$line as returnlist.$linecount
Do returnlist.$assignrow(json.c1,1)
End While

Quit method returnlist


Regards
Bruno

By Design
http://www.bydesign.fr
Bruno Del Sol
bruno.delsol at bydesign.fr
46, rue de La Tour d'Auvergne
75009 Paris (France)

Le 21/04/2021 à 20:58, Mike Matthews - Omnis a écrit :
> Hello All,
>
> I know I can do this, but I just can’t remember, so a Senior Moment for me.
>
> Do OJSON.$listorrowtojson(lvList,kUniTypeCharacter,lvErrorText) Returns 
pfList.vat_bas_nom_json ## Convert LIST data into JSON data
>
> Calculate #S1 as pfList.vat_bas_nom_json ## Check JSON data
>
> Do OJSON.$jsontolistorrow(#S1,lvErrorText) Returns #L1 ## Convert JSON data into List data
>
> So the problem here is #L1 does not look like lvList, by a long way, just a single row, each cell with a list.  I was hoping the JSON was self contained, but no.
>
> lvList has 12 columns, with 12 rows.  All Chars columns.
>
> The JSON data looks like this:
>
> [{"period":"July-20","1220.00":"25376.450000","1640.01":"1.110000","sum":"","1640.05":"0.000000","1640.89":"7774.560000","1102.00":"-1383522.860000","1104.00":"0.000000","1105.00":"-307.500000","1385.00":"118375.680000","sum2":"","1386.00":"36712.460000"},{"period":"August-20","1220.00":"29119.270000","1640.01":"1.110000","sum":"","1640.05":"0.000000","1640.89":"5486.700000","1102.00":"-1230577.190000","1104.00":"0.000000","1105.00":"-294.000000","1385.00":"76638.740000","sum2":"","1386.00":"36712.460000"},{"period":"September-20","1220.00":"31942.070000","1640.01":"1.110000","sum":"","1640.05":"0.000000","1640.89":"942.100000","1102.00":"-996200.960000","1104.00":"0.000000","1105.00":"-158.500000","1385.00":"76550.000000","sum2":"","1386.00":"36712.460000"},{"period":"October-20","1220.00":"20057.790000","1640.01":"1.110000","sum":"","1640.05":"0.000000","1640.89":"293.330000","1102.00":"-972919.280000","1104.00":"0.000000","1105.00":"-4706.480000","1385.00":"80589.600000","sum2":"","1386.00":"41377.210000"},{"period":"November-20","1220.00":"32880.320000","1640.01":"1.110000","sum":"","1640.05":"0.000000","1640.89":"878.670000","1102.00":"-999409.740000","1104.00":"0.000000","1105.00":"-242.910000","1385.00":"80615.200000","sum2":"","1386.00":"39805.210000"},{"period":"December-20","1220.00":"15714.410000","1640.01":"0.000000","sum":"","1640.05":"0.000000","1640.89":"843.080000","1102.00":"-557485.910000","1104.00":"0.000000","1105.00":"-130.000000","1385.00":"77234.130000","sum2":"","1386.00":"39805.210000"},{"period":"January-21","1220.00":"23791.010000","1640.01":"0.000000","sum":"","1640.05":"0.000000","1640.89":"0.000000","1102.00":"-1067034.920000","1104.00":"0.000000","1105.00":"-138.500000","1385.00":"116197.330000","sum2":"","1386.00":"39805.210000"},{"period":"February-21","1220.00":"25510.250000","1640.01":"0.000000","sum":"","1640.05":"0.000000","1640.89":"0.000000","1102.00":"-689436.870000","1104.00":"0.000000","1105.00":"-802.730000","1385.00":"7711
>
> So how do you correctly turn a List into JSON, and then back again?
>
> Thank you
>
> Mike Matthews
>
> Lineal Software Solutions
> Commercial House, The Strand<x-apple-data-detectors://1/1> Barnstaple, Devon, EX31 1EU<x-apple-data-detectors://1/1>
>
> omnis at lineal.co.uk<mailto:mike.matthews at lineal.co.uk>
>
> www.lineal.co.uk<http://www.lineal.co.uk/>
>
> www.sqlworks.co.uk<http://www.sqlworks.co/>
>
>
>
> _____________________________________________________________
> 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