On 16 Nov. 2016, at 8:24 am, Jörgen Stahle <
You could always do something similar in AppleScript. Instead of converting the JSON to a dictionary and then an AS record, leave it as a Cocoa dictionary. Then you can use
valueForKeyPath: in a similar way:
use AppleScript
version "2.4"
-- Yosemite (10.10) or later
use
framework "Foundation"
use scripting additions
on convertJSONToDictionary:jsonString
set
aString to current application's
NSString's stringWithString:jsonString
set
theData to aString's
dataUsingEncoding:(current application's
NSUTF8StringEncoding)
set {theDict,
theError} to current application's
NSJSONSerialization's JSONObjectWithData:theData
options:0
|error|:(reference)
if
theDict is
missing value then error (theError's
localizedDescription() as
text)
number -10000
return
theDict
end convertJSONToDictionary:
set
theJSON to "{\"timeblocksDefs\": {
\"normal\": {
\"morning\": \"06-09\",
\"day\": \"09-18\",
\"primetime\": \"18-22\",
\"nighttime\": \"22-06\"
},
\"lateprime\": {
\"morning\": \"06-09\",
\"day\": \"09-19\",
\"primetime\": \"19-23\",
\"nighttime\": \"23-06\"
}
}}
"
set theDict
to my convertJSONToDictionary:theJSON
set
theResult to (theDict's
valueForKeyPath:"timeblocksDefs.lateprime")
-- convert to AS equivalent
set theResult
to item 1
of ((current application's
NSArray's arrayWithObject:theResult)
as list)