jsonImport or JSONToArray

Douglas Ruisaard dougr at telus.net
Sun Oct 21 18:45:11 EDT 2018


Has anyone recently tried to create a standalone app which includes either a jsonImport or JSONToArray call?

While my code works perfectly when run within the LC API, once a standalone is produced, it chokes  on either one of these calls.  I've reduced the code to its bare essentials.  A sample/simple JSON string I am trying is:

{
 "array": [
   1,
   2,
   3
 ],
 "boolean": true,
 "null": null,
 "number": 123,
 "object": {
   "a": "b",
   "c": "d",
   "e": "f"
 },
 "string": "Hello World"
}

This string is embedded as a Custom Property within a button.  The button calls the following:

on mouseUp

// just empty everything to make sure things are in a known state

     put empty into temp
     put empty into tArray
     put empty into dispArray
     put empty into tJson
     
     get the json of button "ThingSpeak_Fetch"
     put it into testJson
     
// display the JSON before it is converted into an array

     answer "Simple JSON example:" & cr & testJson
     
// this line (either "version") will choke the standalone... it doesn't lock it up in the API

     put JsonToArray(testJson) into tArray
     //put jsonImport(testJson) into tArray
     
     put displayArrayData(tArray,  "") into dispArray
     answer dispArray

end mouseUp

function displayArrayData pArray, pIndent
     # create the variable that loops through the keys in the array
     local tKey
     if pArray is an array then
          # print information to indicate that we are entering a new nested level of the array
          get "Array" & return
          # print full stops that allow the reader to track the depth of an element
          put "." after pIndent
          # create the indentation
          put tab after pIndent
          repeat for each key tKey in pArray
               # call displayArrayData with a nested array
               put format("%s[%s] => %s\n", pIndent, tKey, displayArrayData (pArray[tKey], pIndent)) after it
          end repeat
          delete the last char of it
          return it
     else
          return pArray
     end if 
end displayArrayData

The function call simply outputs the converted array.... and will do so when this code is run from within the API ... but create a Windows standalone and the array output is never generated.

I've tried this in Windows 7 Enterprise SP1, LC: 8.1.9, 8.1.10 and 9.0.1 ... also tried on MAC Sierra (10.12.6) and LC 8.1.9

All platforms behave identically as described above

Any help would be appreciated... meanwhile I'll be submitting this to LC directly

Douglas Ruisaard
Trilogy Software
(250) 573-3935







More information about the use-livecode mailing list