I’m trying to serialize -> deserialize list data in macOS Sierra (10.12.1).
I could serialize it. But I couldn’t de-serialize.
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
set aList to {{theName:"Sound Track", numberOfTimes:1721}, {theName:"Rock", numberOfTimes:942}}
--listed record to XML stype plist string (Serialize)
set anArray to current application's NSArray's arrayWithObject:aList
set pListData to current application's NSPropertyListSerialization's dataFromPropertyList:anArray |format|:(current application's NSPropertyListXMLFormat_v1_0) errorDescription:(missing value)
set bStr to (current application's NSString's alloc()'s initWithData:pListData encoding:(current application's NSUTF8StringEncoding)) as string
(*
--> "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<plist version=\"1.0\">
<array>
<array>
<dict>
<key>numberOfTimes</key>
<integer>1721</integer>
<key>theName</key>
<string>Sound Track</string>
</dict>
<dict>
<key>numberOfTimes</key>
<integer>942</integer>
<key>theName</key>
<string>Rock</string>
</dict>
</array>
</array>
</plist>
"*)
--De-serialize???
set deStr to current application's NSString's stringWithString:bStr
set aDic to current application's NSPropertyListSerialization's propertyListFromData:deStr mutabilityOption:(current application's NSPropertyListMutableContainersAndLeaves) |format|:(missing value) errorDescription:(missing value) ---[__NSCFString bytes]: unrecognized selector sent to instance 0x7fe52d36aab0 error -10000
--> {{theName:"Sound Track", numberOfTimes:1721}, {theName:"Rock", numberOfTimes:942}}--Goal (Not Yet)