1

我有以下 YAML 我正在尝试用 SPYC 解析(https://github.com/mustangostang/spyc/):

children:
    - root:
        - child one
        - child two:
            - subchild one
            - subchild two
        - child three

我希望它返回如下内容:

["children"]=>array(1){
    ["root"]=>array(3){
        [0]=>string(9) "child one",
        ["child two"]=>array(2){
            [0]=>string(12) "subchild one"
            [1]=>string(12) "subchild two"
        }
        [1]=>string(11) "child three"
    }
}

相反,它返回类似这样的内容(包含似乎是一堆空且不必要的数组):

array(4) {
  [0]=>
  array(4) {
    ["root"]=>
    array(0) {
    }
    [0]=>
    string(9) "child one"
    [1]=>
    array(3) {
      ["child two"]=>
      array(0) {
      }
      [0]=>
      string(12) "subchild one"
      [1]=>
      string(12) "subchild two"
    }
    [2]=>
    string(11) "child three"
}

我构建 YAML 内容的方式是否有问题,或者 SPYC(解析器)是否存在已知问题?

谢谢!

4

1 回答 1

1

这是将生成您正在寻找的结构的 YAML

children:
    root:
        child one
        child two:
            subchild one
            subchild two
        child three

在您的初始 YAML 中,-表示您正在启动一个列表/数组。例如,这个 YAML

items:
    - id: 1
      name: ABC

    - id: 2
      name: CDB

生产

[items] => Array
    (
        [0] => Array
            (
                [id] => 1
                [name] => ABC
            )

        [1] => Array
            (
                [id] => 2
                [name] => CDB
            )

    )
于 2012-12-21T01:53:59.963 回答