1

SPYC ( https://github.com/mustangostang/spyc/ )で解析しようとしている次の YAML ビットがあります。

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 に答える