Device Variable Array Returned as String


#1

1) Give a description of the problem
physical device lock ‘lockCodes’ variable is an array but returns a string value

2) What is the expected behavior?
an indexed array in order to get the name or label on the unlock code

3) What is happening/not happening?
a string is returned


do Set variable {codes} = lock’s lockCodes;

…will return a string like…

string codes; /* {“3”:“Bob”,“2”:“Joe”,“1”:“Jim”} */

…when I need an array so that I can use $args.usedCode to determine the name of person that unlocked the door (eg, {codes[$args.usedCode]}). is there a way to force the returned value into an array or easily convert the returned string into an indexed array?

thanks.


#2

this is what I’ve cobbled together so far…

Set variable {codes} = lock's lockCodes;
for ($index = 1 to lock's maxCodes step 1)
do
    Set variable {x} = {mid(codes,indexOf(codes,$index)+length($index)+3)};
    Set variable {names[$index]} = {left(x,indexOf(x,'"'))};
end for;

#3

You might be able to adapt this to what you need.


#4

Were you able to get this to work? This is exactly what I am trying to do now


#5

sorry for the delay, I solved this by parsing the string to find the name that follows the index number.