Structure通过空格来展示。Sequence里的项用”-“来代表,Map里的键值对用”:”分隔. 可以各种组合得到各种结构的数据;
简单序列
- apple
- banana
- carrot
js 里 ['apple', 'banana', 'carrot']
嵌套序列
-
- 1
- 2
-
- 3
- 4
js: [ [ 1, 2 ], [ 3, 4 ] ]
mapping
foo: whatever
bar:
- uno
- dos
js: {
foo: whatever
bar: [ 'uno', 'dos' ]
}
合并关键字
将内容合并到<<:的上级中;
mapping:
name: Joe
job:
name1: teacher
<<:
age: 38
js: { mapping: { name: 'Joe', job: { name1: 'teacher', age: 38 } } }
mapping:
name: Joe
job: Accountant
<<:
age: 38
js: { mapping: { name: 'Joe', job: 'Accountant', age: 38 } }
上面的集合都是通过空格和换行来决定的;下面展示在一行的写法:
简单的集合
---
[ a, b, c ] js:[ a, b, c ]
多行集合
languages: [ Ruby, Perl, Python ]
websites: { YAML: yaml.org,Ruby: ruby-lang.org,
Python: python.org,
Perl: use.perl.org }
js: { languages: [ 'Ruby', 'Perl', 'Python' ],
websites:
{ YAML: 'yaml.org',
Ruby: 'ruby-lang.org',
Python: 'python.org',
Perl: 'use.perl.org' } }
值里面的逗号
集合里的数组是由,分隔的,但是每个逗号后面都要有个空格,这样就可以使用不加引号的数字了;
attendances: [ 45,123, 70,000, 17,222 ]
ruby:{ 'attendances' => [ 45123, 70000, 17222 ] }
基本类型
- 字符串
Be careful using indicators in strings. In particular, the comma, colon, and pound sign must be used carefully.
字符串包括字母和数字字符串,标点符号包括句号,/,空格,",? !等;
注意,一些隐含的字符串如果含有类似下面的情形:
the colon followed by space is an indicator: but is a string:right here
same for the pound sign: here we have it#in a string
the comma can, honestly, be used in most cases: [ but not in, inline collections ]
会被转为js里:
{ 'the colon followed by space is an indicator': 'but is a string:right here',
'same for the pound sign': 'here we have it#in a string',
'the comma can, honestly, be used in most cases': [ 'but not in', 'inline collections' ] }
在ruby语言里使用 !str方法可以将任意类型的数据转为字符串类型:
- Boolean 直接使用true或者false
- 整数
- 浮点数
a simple float: 2.00 larger float: 1,000.09 scientific notation: 1.00009e+3 js: { 'a simple float': 2, 'larger float': '1,000.09', 'scientific notation': 1000.09 }
- Time
有2种写法:ISO8601 format, or a variation which allows spaces between the date, time and time zone iso8601: 2001-12-14t21:59:43.10-05:00 space seperated: 2001-12-14 21:59:43.10 -05:00 js: { iso8601: Sat Dec 15 2001 10:59:43 GMT+0800 (中国标准时间), 'space seperated': Sat Dec 15 2001 10:59:43 GMT+0800 (中国标准时间) }
- Date
--- 1976-07-31 js:Sat Jul 31 1976 08:00:00 GMT+0800 (中国标准时间)
- null
obj: ~ js:{ 'obj': null }
| 块标记符
序列里的折叠块
- apple
- banana
- >
can't you see
the beauty of yaml?
hmm
- dog
js 里:
[ 'apple',
'banana',
'can\'t you see the beauty of yaml? hmm\n',
'dog' ]