2012-12-20 38 views
1

我有YAML以下位我試圖用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(解析器)的已知問題?

謝謝!

回答

1

這是將產生的結構您正在尋找

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

在您最初的YAML 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 
      ) 

    ) 
+1

我的錯誤,謝謝你向我展示我的方式錯誤。現在按預期工作。 – themarkappleby

相關問題