Panos advises me that indeed arrayToJSON does not work out of the box in 
lcserver, although it does work in the IDE and standalones. And that this is 
not a bug.

Let’s call it a lacuna, I suggest in code, Panos concedes in documentation. 

The story is that the mergJSON library, which is accessed from LC on all 
platforms using the mergJSONEncode function, only handles 1-dimensional arrays. 
The arrayToJSON encoder, and the corresponding decoder, use recursive loops to 
extend to multidimensional arrays. These convenience handlers are in a stack 
mergJSONLibrary.livescodecript, which is included in the IDE and standalones, 
but is not (*even* - my emphasis)  distributed with LCserver.

So to use arrayToJSON from LCserver one can upload the library stack - 
available at 
https://github.com/montegoulding/mergJSON/blob/master/mergJSON/mergJSONLibrary.livecodescript
- and then call “start using…”. Or,  more simply, copy the handlers from that 
stack into your own code.

An addition to the  dictionary entries for arrayToJSON and JSONToArray is 
definitely in order. Actually, the two handlers in question can be found in the 
mergJSONEncode and mergJSONDecode dictionary entries, if you first find those 
entries.

I remain rather puzzled that the multi-dimensional array handlers were not 
embedded in the mergJSON C-code library in the first place by Monte or LC when 
they took it over. Blazing speed when communicating with javascript, which is 
where these calls would most likely be used particularly with LCServer, would 
seem to be imperative. Maybe the internal implementation of arrays was yet not 
settled? Whatever, a fix for this code lacuna would be nice, if unlikely to 
happen.

[Actually in my case I wasn't talking to javascript. All I wanted was a way to 
transport an array from the server back to a client.  The  serialisation 
arrayEncode worked for me once I realised the keys and elements of the array 
all had to be in utf-16 encoding, anything in utf-8 could cause the decoding to 
fail. And for safety in sending over the net I also base64encoded - was this 
last step necessary or just paranoia?]

Neville Smythe


 







_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to