I have a script that gets a simple record {|id|:“17” title:“Great page” content:“
Welcome
etc…”}there are many items in this record which come back as an empty string and this causes an error, so in my XML-RPC server I have it send all empty strings as a string “”.
This record is being assigned to the variable “returnArray” in my script.
I then extract the keys to one list and the values to another in the hopes that I can loop through them and then change the actual content of the returnArray record.
For instance, I can manually do: set title of returnArray to “not so great page” and that works fine, but I want to loop through each item in my returnArray, check to see if it is value is equal to “” and then replace it with “”.
Here is what I have:
set theKeys to call method "allKeys" of returnArray
set theValues to call method "allValues" of returnArray
set num to 1 as number
repeat with i in theValues
set theMsg to "KEY => " & (item num of theKeys) & " VALUE => " & (item num of theValues)
if (item num of theValues) is equal to "<!-- empty -->" then
display dialog theMsg
set myKey to (item num of theKeys)
display dialog myKey of returnArray)
end if
set num to num + 1 as number
end repeat
Now I know it is getting the right data, it is finding the items in theValues list that match the “” criteria, and it is successfully pairing that with theKey of that item, so I set myKey to the value of that particular key.
But… when I go to display a dialog (just for tests, eventually will replace data here) it is taking the variable myKey as a literal for a record in return array. This is not at all what I was hoping would happen! Is there any way I can have the myKey variable parsed before it tries to find that value in returnArray so for instance is would be looking for “title” in returnArray instead of myKey?
*** Edit ***
I also tried:
--set myKey to (item num of theKeys)
set myReplace to (item num of theKeys) & " of returnArray"
display dialog myReplace
which just displays the variable myReplace as text, “pageTitle of returnArray” for example, but I don’t want the text, I want the actual value associated with the “pageTitle” of the record “returnArray”. Next I tried…
--set myKey to (item num of theKeys)
set myReplace to (item num of theKeys) & " of returnArray"
display dialog literal of myReplace
also tried “actual of” and “value of”.
but that generates the error Can’t get literal of “pageTitle of returnArray”
This is closer, because what I actually want to get is the pageTitle of returnArray to replace it, but this is still not working as I expected.
Any suggestions?
-sD-
Dr. Scotty Delicious, Scientist.