Sorry for the noob question but I’m embarrassingly stuck.
I’m using xmlrpc to get data to and from a Wordpress site’s Nextgen galleries and I’m trying to iterate through the data that comes back without much success. I’ve stripped it down and replicated the problem with something much simpler that looks like the below. What am I doing wrong?
set dat to {|3|:{pid:1, author:2}, |4|:{pid:2, author:3}}
repeat with theItem in dat
log (theItem) -- breaks here
end repeat
error is “Can’t get item 1 of {|3|:{pid:1, author:2}, |4|:{pid:2, author:3}}.” number -1728 from item 1 of {|3|:{pid:1, author:2}, |4|:{pid:2, author:3}}"
your collection type is a record (dictionary) which cannot be enumerated like a list (array) in vanilla AppleScript.
But you can do it with a little help of Cocoa (AppleScriptObkC)
use framework "Foundation"
set dat to {|3|:{pid:1, author:2}, |4|:{pid:2, author:3}}
set cocoaDictionary to current application's NSDictionary's dictionaryWithDictionary:dat
repeat with aKey in (get cocoaDictionary's allKeys())
set theValue to (cocoaDictionary's objectForKey:aKey) as record
display dialog "pid: " & theValue's pid & " - " & "author: " & theValue's author
end repeat