AppleScript名:YAMLのじっけん4 |
— Created 2017-02-16 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "YAML" –https://github.com/mirek/YAML.framework –YAMLの文字列からオブジェクトを生成する set aYAMLstr to " – name: Smith email: smith@mail.com – name: Shelton email: shelton@mail.com – name: Kelly email: kelly@mail.com " set aRes to (retObjectFromYAMLString(aYAMLstr) of me) as list of string or string log result –> {{{name:"Smith", email:"smith@mail.com"}, {name:"Shelton", email:"shelton@mail.com"}, {name:"Kelly", email:"kelly@mail.com"}}} set bYAMLstr to " names: [Smith, Shelton, Kelly] emails: [smith@mail.com, shelton@mail.com, kelly@mail.com] " set bRes to retObjectFromYAMLString(bYAMLstr) of me log result –> {{names:{"Smith", "Shelton", "Kelly"}, emails:{"smith@mail.com", "shelton@mail.com", "kelly@mail.com"}}} –オブジェクト(list)からYAMLの文字列を生成する set bStr to retYAMLStringFromObject(bRes) log result (* "— – names: – Smith – Shelton – Kelly emails: – smith@mail.com – shelton@mail.com – kelly@mail.com … " *) on retObjectFromYAMLString(aYAMLstr as string) set aStr to current application’s NSString’s stringWithString:aYAMLstr set aData to aStr’s dataUsingEncoding:(current application’s NSUTF8StringEncoding) set aData to current application’s YAMLSerialization’s objectsWithYAMLString:aStr options:(4096) |error|:(missing value) return aData as list of string or string end retObjectFromYAMLString on retYAMLStringFromObject(anObject) set aString to (current application’s YAMLSerialization’s createYAMLStringWithObject:anObject options:(1) |error|:(missing value)) as list of string or string return aString end retYAMLStringFromObject |
More from my site
(Visited 56 times, 1 visits today)