Multidimensional array issue

HENRY LOWE hlowe at me.com
Mon Mar 8 18:46:32 EST 2021


I am using multidimensional arrays to process data read from JSON files.

Some of the data in the JSON files can be represented in alternative forms in files from different sources.

For example a field named “status” may be represented as either:

“status": {
    "text": “active"}

or

“status": {“active”}

To recognize both forms I use code (after transforming JSON to an array tArray] such as:

Local tArray, tStatus

Put tArray[“status”] into tStatus
If tStatus is empty then
	put tArray[“status”][“text”] into tStatus
End if

I have discovered that if tArray[“status”][“text”] contains a value then tArray[“status”] is not empty (as expected), so my test fails. 

However the expression ‘the value of tArray[“status”]’ return empty and calling  - answer tArray[“status”] returns an empty (null) string.

Is this a bug or a (perhaps) a logical outcome of how LC implements arrays?

I have often used the form 'if tArray[“key1”] is empty' to determine whether an array element hold a value but this breaks if tArray[“key1”][“key2”] holds a value.

Try the following in the message box: put "data" into tA["A"]["B"];answer tA["A"] is empty

The result is false! Livecode reports that tA[“A”] is not empty

However entering the following in the message box returns true!

 put "data" into tA["A"]["B"];answer the value of tA["A"] is empty

Henry





More information about the use-livecode mailing list