Hi Alex,

the JSONtoArray() function is part of the mergJSON external.
The README of this external describes how to use this function
and it's counterpart JSONtoArray as follows:

This external has been implemented to encode/decode UTF8 JSON to a LiveCode 
array as quickly as possible. Currently externals can not work with 
multi-dimensional LiveCode arrays so the intention is it is used with two 
functions like this:

        -- pArray - array to be encoded
        -- pForceRootType - can force the root to be an object if it looks like 
an array
        -- pPretty - include whitespace
        function ArrayToJSON pArray,pForceRootType,pPretty
           repeat for each key tKey in pArray
              if pArray[tKey] is an array then
                 put "}"&ArrayToJSON(pArray[tKey]) into pArray[tKey]
              end if
           end repeat
           return(mergJSONEncode("pArray",pForceRootType,pPretty))
        end ArrayToJSON

        function JSONToArray pJSON
           local tArray,tKeys
           repeat for each line tKey in mergJSONDecode(pJSON,"tArray")
              put JSONToArray(tArray[tKey]) into tArray[tKey]
           end repeat
           return tArray
        end JSONToArray

For most cases the above is all the documentaion you will need. There are 
however some quirks to the external you might need to know about.


Another option would be to load the JSON extension and to use
the JsonImport() function.


Ralf



On 23.06.22 01:31, Alex Tweedly via use-livecode wrote:

On 22/06/2022 17:02, Richard Gaskin via use-livecode wrote:
[ ... about using JSON ... ]
But if you don't need interoperability, you wouldn't need to write a parser, since LC includes a good one built into the engine.

What did I miss?

The fact that Livecode's support for JSON is, hmmm, mediocre at best ??

The parser "built-in" seems to work fine in the IDE, but not on the server :

<?lc
set the errormode to inline
put the version

put "{'name':'asdf'}" into t
replace "'" with quote in t
put JSONtoarray(t) into tA
put the keys of tA

fails with -

file "/home/alextwee/public_html/rampuk/tJSON.lc"
   row 7, col 5: Function: error in function handler (JSONtoarray)
   row 7, col 5: put: error in expression

(there's no mention of any platform restricitons in the dictionary).

I tried copying in the sample ode for wrapping JSONToArray around mergJSONDecode,
which then fails with "error in function handler mergJSONDecode.


(I must admit I encountered this a while ago, figured it was probably a temporary issue so I replaced JSON by LSON, and forgot all about it.) This discussion prompted me to re-try it.

I can't believe this problem isn't causing widespread problems, so it's probably something specific about me, or my on-rev account. If anyone has suggestions, I'll
try them; if not, I'll put it as a bug report into QCC see what happens.

Alex.



_______________________________________________
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