AppleScript名:listのrecordをplistにserializeして、plistをde-serializeする |
— Created 2016-10-30 by Takaaki Naganoya — Modified 2016-10-31 by Shane Stanley — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" set aList to {{theName:"サウンドトラック", numberOfTimes:1721}, {theName:"ロック", numberOfTimes:942}, {theName:"クラシック", numberOfTimes:539}, {theName:"ポップ", numberOfTimes:492}, {theName:"J-Pop", numberOfTimes:352}, {theName:"アニメ", numberOfTimes:330}, {theName:"Pop", numberOfTimes:279}, {theName:"World", numberOfTimes:218}, {theName:"Soundtrack", numberOfTimes:188}, {theName:"ジャズ", numberOfTimes:187}, {theName:"エレクトロニック", numberOfTimes:166}, {theName:"Classical", numberOfTimes:165}, {theName:"Rock", numberOfTimes:148}, {theName:"R&B", numberOfTimes:125}, {theName:"ニューエイジ", numberOfTimes:104}, {theName:"Unclassifiable", numberOfTimes:81}, {theName:"Children’s", numberOfTimes:57}, {theName:"歌謡曲", numberOfTimes:47}, {theName:"Holiday", numberOfTimes:38}, {theName:"オルタナティブ", numberOfTimes:34}, {theName:"Data", numberOfTimes:32}, {theName:"イージーリスニング", numberOfTimes:31}, {theName:"ヴォーカル", numberOfTimes:28}, {theName:"ワールド", numberOfTimes:28}, {theName:"soundtrack", numberOfTimes:19}, {theName:"ディズニー", numberOfTimes:15}, {theName:"シンガーソングライター", numberOfTimes:15}, {theName:"ブルース", numberOfTimes:15}, {theName:"Easy Listening", numberOfTimes:14}, {theName:"ラテン", numberOfTimes:14}, {theName:"Electronica/Dance", numberOfTimes:14}, {theName:"Anime", numberOfTimes:13}, {theName:"フォーク", numberOfTimes:10}, {theName:"J-POP", numberOfTimes:9}, {theName:"New Age", numberOfTimes:9}, {theName:"ダンス", numberOfTimes:5}, {theName:"ホリデー", numberOfTimes:5}, {theName:"カントリー", numberOfTimes:4}, {theName:"演歌", numberOfTimes:4}, {theName:"Latin", numberOfTimes:3}, {theName:"ヒップホップ/ラップ", numberOfTimes:3}, {theName:"Vocal", numberOfTimes:2}, {theName:"R&B/ソウル", numberOfTimes:2}, {theName:"R&B/ソウル", numberOfTimes:2}, {theName:"#NIPPONSEI @ IRC.MIRCX.COM", numberOfTimes:2}, {theName:"148", numberOfTimes:1}, {theName:"Electronic", numberOfTimes:1}, {theName:"Folk", numberOfTimes:1}, {theName:"NHK FM(東京)", numberOfTimes:1}, {theName:"その他", numberOfTimes:1}, {theName:"チルドレン・ミュージック", numberOfTimes:1}, {theName:"Seattle Pacific University – Latin", numberOfTimes:1}, {theName:"Kayokyoku", numberOfTimes:1}, {theName:"ヒップホップ/ ラップ", numberOfTimes:1}, {theName:"Dance", numberOfTimes:1}, {theName:"インストゥルメンタル", numberOfTimes:1}, {theName:"146", numberOfTimes:1}} set aRes to serializeToPlistString(aList) of me –>"<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version=\"1.0\"><array><dict><key>numberOfTimes</key><integer>1721</integer><key>theName</key><string>サウンドトラック</string></dict>…. set bRes to (deserializeToPlistString(aRes) of me) as list –> {{numberOfTimes:1721, theName:"Sound Track"}, {numberOfTimes:942, theName:"Rock"}} –list or record –> XML-format plist string on serializeToPlistString(aList as {list, record}) set pListData to current application’s NSPropertyListSerialization’s dataWithPropertyList:aList |format|:(current application’s NSPropertyListXMLFormat_v1_0) options:0 |error|:(missing value) set bStr to (current application’s NSString’s alloc()’s initWithData:pListData encoding:(current application’s NSUTF8StringEncoding)) as string return bStr end serializeToPlistString –XML-format plist string–> list or record on deserializeToPlistString(aStr as string) set deStr to current application’s NSString’s stringWithString:aStr set theData to deStr’s dataUsingEncoding:(current application’s NSUTF8StringEncoding) set aList to current application’s NSPropertyListSerialization’s propertyListWithData:theData options:(current application’s NSPropertyListMutableContainersAndLeaves) |format|:(missing value) |error|:(missing value) return aList end deserializeToPlistString |
More from my site
(Visited 16 times, 1 visits today)