如何在 YAML 中转义指示符(即 : 或 - ) [英] How to escape indicator characters (i.e. : or - ) in YAML

查看:34
本文介绍了如何在 YAML 中转义指示符(即 : 或 - )的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在配置文件中,我有一个希望为其分配 URL 的键.问题是 YAML 将 : 和 - 字符解释为创建映射或列表,因此该行存在问题

In a config file, I have a key to which I wish to assign a URL. The problem is that YAML interprets : and - characters as either creating mappings or lists, so it has a problem with the line

url: http://www.example-site.com/

(都是因为http后面的冒号和中间的连字符)

(both because of the colon following http and the hyphen in the middle)

是否有明确的方式来逃避 ':' 和 '-' ?或者将整个内容放在单引号中并收工是否可行?

Is there an explicit way to escape ':' and '-' ? Or would it work to just put the whole thing in single quotes and call it a day?

推荐答案

引用:

"url: http://www.example-site.com/"

为了澄清,我的意思是引用价值",最初认为整个事情就是价值.如果 http://www.example-site.com/ 是值,只需像这样引用它:

To clarify, I meant "quote the value" and originally thought the entire thing was the value. If http://www.example-site.com/ is the value, just quote it like so:

url: "http://www.example-site.com/"

这篇关于如何在 YAML 中转义指示符(即 : 或 - )的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆