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

查看:2089
本文介绍了如何在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天全站免登陆