Matt Haughton
Matt Haughton

Reputation: 2980

JsonToArray and ArrayToJson on LiveCode Server

The functions JsonToArray and ArrayToJson work fine on LC normally, however I recently tried to use these functions on LC Server and they don't work, just get the error

Function: error in function handler (JSONToArray)

So, I've resorted to using fastjson for now, however I'd love to use the same code for server that I use in LC apps (there are nuanced differences between fastjson and the native functions).

I've done a fair bit of searching but haven't found a definitive answer on how to get these functions working on server.

Following is the set up I'm testing on

Any guidance would be most appreciated.

Upvotes: 1

Views: 416

Answers (1)

Devin
Devin

Reputation: 603

External libraries like this are not automatically included in the LiveCode Server build. You have to move the library to your server manually, then load the extension you want to use. I have not done this exact thing but I did need to use the JSonExport and JSonImport functions in a LC server script. This is what I had to do:

  1. Find the files for libraries that define this function in the desktop version of your LiveCode installation. If you look up the function in the Dictionary, you'll find the name of the library under Associations. In my example the library can be found by going to your LiveCode folder in Programs(X86) and looking in Tools\Extensions. My functions were in the library com.livecode.library.json.
  2. Copy the library folder to your LC server. I just copied the whole folder to the same folder as the .lc file calling the function.
  3. Load the extension in your .lc file, like this:

    load extension from file "com.livecode.library.json/module.lcm"

After that you should be able to call the function(s). I assume the procedure would be similar for your JSONToArray call. I did notice that the library for your function is mergJSON, which can be found in Tools\Ext\mergJSON-1.0.56. There is no .lcm (a LiveCode Builder binary) file in that folder, so it may be you'll have to load the .dll file. Experimentation is in order.

Upvotes: 1

Related Questions