这是有效的YAML吗? [英] Is this valid YAML?
问题描述
因此,对于我在C#中的文本解析问题,我得到了针对YAML.我被推荐的那个图书馆撞到了墙,所以这是个速记.
So for my text parsing in C# question, I got directed at YAML. I'm hitting a wall with this library I was recommended, so this is a quickie.
heading:
name: A name
taco: Yes
age: 32
heading:
name: Another name
taco: No
age: 27
以此类推.那有效吗?
推荐答案
部分地. YAML支持多个连续的文档"的概念.如果这是您要在此处执行的操作,那么是的,它是正确的-您有两个文档(或文档片段).为了使其更加明确,您应该将它们用三个破折号隔开,如下所示:
Partially. YAML supports the notion of multiple consecutive "documents". If this is what you are trying to do here, then yes, it is correct - you have two documents (or document fragments). To make it more explicit, you should separate them with three dashes, like this:
---
heading:
name: A name
taco: Yes
age: 32
---
heading:
name: Another name
taco: No
age: 27
另一方面,如果希望将它们包含在同一文档中(以便反序列化它们将导致包含两个元素的列表),则应像下面这样编写.缩进级别要格外小心:
On the other hand if you wish to make them part of the same document (so that deserializing them would result in a list with two elements), you should write it like the following. Take extra care with the indentation level:
- heading:
name: A name
taco: Yes
age: 32
- heading:
name: Another name
taco: No
age: 27
通常,YAML简洁明了,可人工读取/编辑,但实际上并非可人工编写,因此应始终使用库来生成它.另外,请注意,不同版本的YAML之间存在一些重大变化,如果您使用的是符合标准不同版本的不同语言的库,这可能会给您带来麻烦.
In general YAML is concise and human readable / editable, but not really human writable, so you should always use libraries to generate it. Also, take care that there exists some breaking changes between different versions of YAML, which can bite you if you are using libraries in different languages which conform to different versions of the standard.
这篇关于这是有效的YAML吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!