我知道这是一个旧的 Q,但现在有可能访问键和值(10.9+)。在 10.9 中,您需要使用脚本库来运行它,在 10.10 中,您可以直接在脚本编辑器中使用代码:
use framework "Foundation"
set testRecord to {a:"aaa", b:"bbb", c:"ccc"}
set objCDictionary to current application's NSDictionary's dictionaryWithDictionary:testRecord
set allKeys to objCDictionary's allKeys()
repeat with theKey in allKeys
log theKey as text
log (objCDictionary's valueForKey:theKey) as text
end repeat
这不是破解或解决方法。它只是使用“新”功能从 AppleScript 访问 Objective-C-Objects。在搜索其他主题的过程中发现了这个问题,无法抗拒回答;-)
更新以提供 JSON 功能:
当然,我们可以更深入地研究 Foundation 类并使用 NSJSONSerialization 对象:
use framework "Foundation"
set testRecord to {a:"aaa", b:"bbb", c:"ccc"}
set objCDictionary to current application's NSDictionary's dictionaryWithDictionary:testRecord
set {jsonDictionary, anError} to current application's NSJSONSerialization's dataWithJSONObject:objCDictionary options:(current application's NSJSONWritingPrettyPrinted) |error|:(reference)
if jsonDictionary is missing value then
log "An error occured: " & anError as text
else
log (current application's NSString's alloc()'s initWithData:jsonDictionary encoding:(current application's NSUTF8StringEncoding)) as text
end if
玩得开心,迈克尔/汉堡