Yaml 问题,在 Yaml 中存储某些类型的字符是否存在任何问题?
我对 yaml 很陌生,我只想知道我可以和不能在 yaml 中存储什么字符?
双引号等的转义字符是什么?
我可以跨多行吗?
I'm very new to yaml, and I just want to know what I can and can't store character wise in yaml?
What are the escape characters for double quotes etc?
Can I span multiple lines?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本上,你可以存储所有东西。引号不是问题,您可以在不带引号的情况下键入文本(对于不能随意合并的不可打印字符,有常见的转义序列)。这意味着纯数字文本被视为数字,但话又说回来,您可以添加引号或显式类型注释(我假设大多数库在必要时都会这样做),例如
!!str 100
。另外,如果您想包含注释符号 (#
),则必须添加引号。另一个问题是,某些字符串可能看起来像更复杂的 YAML(例如,感叹号的某些用法看起来像强制转换,冒号的某些用法看起来像单例关联表)。您可以通过使用仅由单行组成的“多行”字符串来避免这些问题。多行字符串存在并有两种形式,保留换行符 (
--- |
) 并忽略除空行之外的换行符 (--- >
,很像 markdown )。Basically, you can store everything. Quotes aren't an issue, you can type text out without quotes (and for non-printable characters that you can't incorporate casually, there are the usual escape sequences). That means purely numerical text is considered a number, though - but then again, you can add quotes or an explicit type annotation (and I assume most libraries do that when necessary), e.g.
!!str 100
. Also, if you want to include the comment sign (#
), you have to add quotes.Another issue is that some strings may look like more complex YAML (e.g. certain uses of exclamation signs look like casts and certain uses of colons look like singleton associative tables). You can avoid these by using "multi-line" strings that just consist of a single line. Multi-line strings exist and come in two flavors, preserving linebreaks (
--- |
) and ignoring newlines except for blank lines (--- >
, much like markdown).