本文共 1117 字,大约阅读时间需要 3 分钟。
yaml是一个数据序列化的标准,适用于所有开发语言,最大的特点是可读性好。
yaml的一个主要应用方向就是编写配置文件,有非常多的系统和框架采用yaml进行配置。
yaml有以下基本规则:
1、大小写敏感 2、使用缩进表示层级关系 3、禁止使用tab缩进,只能使用空格键 4、缩进长度没有限制,只要元素对齐就表示这些元素属于一个层级。 5、使用#表示注释 6、字符串可以不用引号标注
map, list, scalar
使用冒号:表示键值对,同一缩进的所有键值对属于一个map
age : 12name : beita
使用连字符(-)表示:
# yaml表示:- a- b- 1# 对应Json表示:['a','b',1]也可以写在一行:# yaml表示:[a, b, c]# 对应Json表示:['a', 'b', 'c']
数据最小的单位,不可以再分割
# YAML表示websites: YAML: yaml.org Ruby: ruby-lang.org Python: python.org Perl: use.perl.org# 对应Json表示{ websites: { YAML: 'yaml.org', Ruby: 'ruby-lang.org', Python: 'python.org', Perl: 'use.perl.org' } }
# YAML表示languages: - Ruby - Perl - Python - c# 对应Json表示{ languages: [ 'Ruby', 'Perl', 'Python', 'c' ] }
# YAML表示- - Ruby - Perl - Python- - c - c++ - java# 对应Json表示[ [ 'Ruby', 'Perl', 'Python' ], [ 'c', 'c++', 'java' ] ]# 方法2- - Ruby - Perl - Python- - c - c++ - java# 方法3- [Ruby,Perl,Python]- [c,c++,java]
# YAML表示- id: 1 name: li- id: 2 name: liu# 对应Json表示[ { id: 1, name: 'li' }, { id: 2, name: 'liu' } ]
转载地址:http://wnaui.baihongyu.com/