鉴于以下简单的 yaml 数据,
foo: 1
bar:
- one
- two
Run Code Online (Sandbox Code Playgroud)
如果我想创建一个完全相同数据结构的数组,正确的方法是什么?
我试过了
first:
foo: 1
bar:
- one
- two
- three
second:
foo: 2
bar:
- one1
- two2
- three3
Run Code Online (Sandbox Code Playgroud)
或者,
- foo: 1
bar:
- one
- two
- three
- foo: 2
bar:
- one1
- two2
- three3
Run Code Online (Sandbox Code Playgroud)
并且,
- first:
foo: 1
bar:
- one
- two
- three
- second:
foo: 2
bar:
- one1
- two2
- three3
Run Code Online (Sandbox Code Playgroud)
但似乎没有一个是正确的方法。有什么帮助吗?谢谢!
我想你是在追求这个:
- foo: 1
bar:
- one
- two
- three
- foo: 2
bar:
- one1
- two2
- three3
Run Code Online (Sandbox Code Playgroud)
这给了你这个结构:
[
{
"foo": 1,
"bar": [
"one",
"two",
"three"
]
},
{
"foo": 2,
"bar": [
"one1",
"two2",
"three3"
]
}
]
Run Code Online (Sandbox Code Playgroud)
或者,如果“第一”和“第二”标签对您很重要:
first:
foo: 1
bar:
- one
- two
- three
second:
foo: 2
bar:
- one1
- two2
- three3
Run Code Online (Sandbox Code Playgroud)
这为您提供了一个字典/关联数组:
{
"second": {
"foo": 2,
"bar": [
"one1",
"two2",
"three3"
]
},
"first": {
"foo": 1,
"bar": [
"one",
"two",
"three"
]
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5124 次 |
| 最近记录: |