AppleScript名:YAMLのじっけん5 |
— 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の文字列からオブジェクトを生成する(1) set aYAMLstr to " — # お好みの映画、ブロック形式 – Casablanca – Spellbound – Notorious — # 買い物リスト、インライン形式、またはフロー形式 [milk, bread, eggs] " set aRes to retObjectFromYAMLString(aYAMLstr) of me log result –> {{"Casablanca", "Spellbound", "Notorious"}, {"milk", "bread", "eggs"}} –YAMLの文字列からオブジェクトを生成する(2) set aYAMLstr to " – {name: John Smith, age: 33} – name: Mary Smith age: 27 " set aRes to retObjectFromYAMLString(aYAMLstr) of me log result –> {{{name:"John Smith", age:"33"}, {name:"Mary Smith", age:"27"}}} –YAMLの文字列からオブジェクトを生成する(3) set aYAMLstr to " men: [John Smith, Bill Jones] women: – Mary Smith – Susan Williams" set aRes to retObjectFromYAMLString(aYAMLstr) of me log result –> {{men:{"John Smith", "Bill Jones"}, women:{"Mary Smith", "Susan Williams"}}} 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 68 times, 1 visits today)