博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
关于yaml配置文件的使用
阅读量:3986 次
发布时间:2019-05-24

本文共 1117 字,大约阅读时间需要 3 分钟。

yaml是一个数据序列化的标准,适用于所有开发语言,最大的特点是可读性好。

yaml的一个主要应用方向就是编写配置文件,有非常多的系统和框架采用yaml进行配置。

yaml有以下基本规则:

1、大小写敏感 2、使用缩进表示层级关系 3、禁止使用tab缩进,只能使用空格键 4、缩进长度没有限制,只要元素对齐就表示这些元素属于一个层级。 5、使用#表示注释 6、字符串可以不用引号标注

三种数据结构

map, list, scalar

map,散列表

使用冒号:表示键值对,同一缩进的所有键值对属于一个map

age : 12name : beita

list,数组

使用连字符(-)表示:

# yaml表示:- a- b- 1# 对应Json表示:['a','b',1]也可以写在一行:# yaml表示:[a, b, c]# 对应Json表示:['a', 'b', 'c']

scalar,纯量

数据最小的单位,不可以再分割

数据结构嵌套

map嵌套map

# 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' } }

map嵌套list

# YAML表示languages: - Ruby - Perl - Python - c# 对应Json表示{
languages: [ 'Ruby', 'Perl', 'Python', 'c' ] }

list嵌套list

# 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]

list嵌套map

# YAML表示-  id: 1  name: li-  id: 2  name: liu# 对应Json表示[ {
id: 1, name: 'li' }, {
id: 2, name: 'liu' } ]

转载地址:http://wnaui.baihongyu.com/

你可能感兴趣的文章
[LeetCode By Python]13 Roman to Integer
查看>>
[leetCode By Python] 14. Longest Common Prefix
查看>>
[LeetCode By Python]107. Binary Tree Level Order Traversal II
查看>>
[LeetCode By Python]108. Convert Sorted Array to Binary Search Tree
查看>>
[leetCode By Python]111. Minimum Depth of Binary Tree
查看>>
[LeetCode By Python]112. Path Sum
查看>>
[LeetCode By Python]118. Pascal's Triangle
查看>>
[LeetCode By Python]119. Pascal's Triangle II
查看>>
[LeetCode By Python]121. Best Time to Buy and Sell Stock
查看>>
[LeetCode By Python]122. Best Time to Buy and Sell Stock II
查看>>
[LeetCode By Python]125. Valid Palindrome
查看>>
[LeetCode By Python]136. Single Number
查看>>
[LeetCode BY Python]155. Min Stack
查看>>
[LeetCode By Python]167. Two Sum II - Input array is sorted
查看>>
[LeetCode By Python]168. Excel Sheet Column Title
查看>>
[LeetCode BY Python]169. Majority Element
查看>>
[LeetCode By Python]171. Excel Sheet Column Number
查看>>
[LeetCode By Python]172. Factorial Trailing Zeroes
查看>>
[LeetCode By MYSQL] Combine Two Tables
查看>>
Mac删除文件&文件夹
查看>>