这是有效的 YAML 吗? [英] Is this valid YAML?

查看:17
本文介绍了这是有效的 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屋!

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