YAML

对象

  • 使用对象键值对
1
2
3
key:
	child-key1: value1
	child-key2: value2
  • 当对象较复杂,比如为数组

  • 问号加一个空格代表一个复杂的 key

  • 一个冒号加一个空格代表一个 value

1
2
3
4
5
6
? 
	- complexkey1
	- complexkey2
: 
	- complexvalue1
	- complexvalue2

数组

  1. -开头的行表示一个数组
1
2
- A
- B
  1. 支持多维数组
1
2
3
4
5
6
7
8
9
# 行内表示
key: [value1,value2]

# 多行表示

-
 - A
 - B
 - C
  1. 很多元素$\rightarrow$数组元素$\rightarrow$数组
  • 例子
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
companies:
    -
        id: 1
        name: company1
        price: 200W
    -
        id: 2
        name: company2
        price: 500W
# 或者
companies: [{id: 1,name: company1,price: 200W},{id: 2,name: company2,price: 500W}]

复合结构

1
2
3
4
5
6
7
8
9
languages:
  - Ruby
  - Perl
  - Python 
websites:
  YAML: yaml.org 
  Ruby: ruby-lang.org 
  Python: python.org 
  Perl: use.perl.org

纯量

定义

最基本、不可再分的值

分类

  1. 字符串
1
2
3
4
5
string:
	- 哈哈
	- 'Egnlish word'
	- newline
	  newline2 #字符串可以被拆成多行,每行会被转换成一个空格
  1. 布尔值
1
2
3
boolean:
	- True # 或者true
	- False # 或者false
  1. 整数和浮点数
1
2
3
4
5
6
float:
	- 3.14
	- 8.85E-12 # 可以使用科学记数法
int:
	- 123
	- 0b1010_0111_0100_1010_1110 # 二进制表示
  1. Null
1
2
3
null:
	nodeName: 'node'
	parent: ~ # ~表示null
  1. 日期
1
2
date:
	- 2023-2-11 # 必须是这种格式
  1. 时间
1
2023-2-11T22:07:02+8:00 # 用+代表时区

引用(暂定)

Licensed under CC BY-NC-SA 4.0
comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy