App Programming‎ > ‎

Easyjson

What is EasyJSON?

EasyJSON is a JSON parser for LiveCode, written solely in LiveCode. Use it to put JSON data directly into LiveCode arrays, and to turn a LiveCode array into a valid JSON document.

Alternatives to EasyJSON

Because it is a LiveCode script, EasyJSON can run relatively slowly, compared to an external library, written in a lower-level language. The prolific Monte Goulding has produced an external JSON parser for LiveCode, mergJSON, which runs many orders of magnitude faster than EasyJSON. His acclaimed externals can be found on http://mergext.com.

EasyJSON is based on a LiveCode JSON library originally written by the late Mark Smith. That library can still be found and downloaded online. Some of the code in the script was based on some great code originally developed by Andre Garzia (http://www.andregarzia.com).

How to Use EasyJSON

A. Inserting the Code into your program

1. Go to To Easyjson.lc and copy the script without the first ("<?lc") and last lines ("?>")  
2. Paste it into your stack script

    There are only 2 functions that you are likely to ever need:

    • arrayFromJSON( pJson ) - takes JSON data and returns a valid LiveCode array. It expects the JSON data to be presented as a valid JSON document, as described in http://json.org.
    • jsonFromArray( pArray ) - takes in a LiveCode array, and returns a valid JSON document string.

These 2 functions in turn require other functions that are part of the EasyJSON library, but you are unlikely to use them directly. If you want more detailed information on how these functions work, have a look at the (heavily commented) script.

B. Using the Functions:

1. To read JSON data into a LiveCode array:

    put field "dataIn" into myJSON
    put arrayFromJSON(myJSON) into myArray

    You can not retrieve your 


License

Comments