Yaml多行文本格式
Yaml支持多行的字符串格式,可以通过下面两种格式指定:

Block Scalars
Flow Scalars
Block Scalars
Block Scalars格式的字符串由两部分组成:Scalar header 和 字符串
下面就是一个Block scalar字符串的例子:

example: >
Several lines of text,
with some “quotes” of various ‘types’,
and also a blank line:

plus another line at the end.

1
2
3
4
5
6
7
8
Scalars Header包含三种类型的Header:

Block Style Indicator
> 表示将字符串中的换行符替换为空格
| 表示将字符串中的换行符保留

Block Chomping Indicator
– 删除字符串后面所有的空行
**+**保留字符串后面所有的空行
默认是留空,意思是仅保留一行空行

Indentation Indicator
yaml的spec对缩进比较严格,具体来说根节点的缩进距离是由第一个非空行决定的,假如第一个非空行的缩进为2个space,则其子节目的缩进必需不能小于2。

Example
保留换行
example: |-
Several lines of text,
with some “quotes” of various ‘types’,
and also a blank line:

plus another line at the end.

1
2
3
4
5
6
7
8
如果使用Jackjson ObjectMapper反序列化后得到的字符串为:

Several lines of text,
with some “quotes” of various ‘types’,
and also a blank line:
plus another line at the end.
1
2
3
4
换行替换为空格
example: >-
Several lines of text,
with some “quotes” of various ‘types’,
and also a blank line:

plus another line at the end.

1
2
3
4
5
6
7
得到的字符串:

Several lines of text, with some “quotes” of various ‘types’, and also a blank line:
plus another line at the end.
1
2
参考: Yaml Multiline
————————————————
版权声明:本文为CSDN博主「林大虫子」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/west_609/article/details/105968315

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注