首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >何时在Symfony YAML组件中编号嵌套序列?

何时在Symfony YAML组件中编号嵌套序列?
EN

Stack Overflow用户
提问于 2015-01-03 20:20:56
回答 1查看 229关注 0票数 0

我使用Symfony YAML组件来解析Flexget配置文件。然而,有时它会将电视节目序列转换为编号列表,而实际上它应该是一个带有破折号的列表( - )。

错误的例子:

代码语言:javascript
复制
templates:
  tv:
    private_torrents: no
    regexp:
      accept:
        12: 'Absolute Duo'
        13: 'Yuri Kuma Arashi'
        14: 'Miritari!'
        ...

正确的例子:

代码语言:javascript
复制
templates:
  tv:
    private_torrents: no
    regexp:
      accept:
        - 'Absolute Duo'
        - 'Yuri Kuma Arashi'
        - 'Miritari!'
        ...

我怎样才能防止这种情况发生?

这就是我如何将YAML转储到文件:$config = Yaml::dump($this->config, 99, 2);

我使用99是因为我从不想要内联配置。

我正在转储的配置:

代码语言:javascript
复制
array (size=2)
  'templates' => 
    array (size=1)
      'tv' => 
        array (size=4)
          'private_torrents' => string 'no' (length=2)
          'regexp' => 
            array (size=1)
              'accept' => 
                array (size=9)
                  0 => string 'Shingeki no Bahamut' (length=19)
                  1 => string 'Sora no Method' (length=14)
                  2 => string 'Gugure! Kokkuri-san' (length=19)
                  3 => string 'Majin Bone' (length=10)
                  4 => string 'Grisaia no Kajitsu' (length=18)
                  5 => string 'Queen's Blade Rurou no Senshi' (length=29)
                  6 => string 'Daitoshokan no Hitsujikai' (length=25)
                  7 => string 'Trinity Seven' (length=13)
                  8 => string 'Akame ga Kill!' (length=14)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-03 21:27:17

你会发布你正在转储的配置输入吗?

此外,我猜问题的唯一原因可能是,您的输入被视为哈希,查看这一行显示,如果您的数组不包含从0到count-1之间的键,则您的输入将被视为散列:

https://github.com/symfony/Yaml/blob/master/Dumper.php#L57

如果被认为是散列,而不是输出"-",它将输出"key: value" yaml。

https://github.com/symfony/Yaml/blob/master/Dumper.php#L64

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27759141

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档