2011-05-18 99 views
2

我是新来YAML,并试图做一个YAML块,但我收到以下错误YAML块:错误而解析文本

while scanning a block mapping: expected , but found: #< ScalarToken Value="content: | This is a test of a test test test test A very very good test yeah yeah A test of test test" Style="None"> (line 8, column 1)

虽然作品,未经精|,我想空白保存。

YAML文件(Home.yml):

--- 
section: 
    title: About this site 
    content: | 
     This is a test of a test test test test 
     A very very good test 
     A test of test test 
section: 
    title: Source code 
    content: | 
     Licens:: BSD 
     Link:: Here 
     Foo 
... 

Ruby代码:

home = YAML.load_file('data/Home.yml') 
home.inspect 

回答

1

哪些YAML解析器您使用的? Ruby 1.8.7解析器和1.9中的解析器在你的问题中解析YAML。

还有问题,通过。你给的语法是这样的哈希:

{ 
    'section' => { 
    'title' => "About this site", 
    'content => ... 
    } 
    'section' => { 
    'title' => 'Source code', 
    'content' => ... 
    } 
} 

但是,你不能有两个哈希键是相同的。发生的是最后一个胜利。您可能正在寻找一组哈希。要做到这一点,利用这个YAML语法:

--- 
- 
    section: 
    title: About this site 
    content: | 
     This is a test of a test test test test 
     A very very good test 
     A test of test test 
- 
    section: 
    title: Source code 
    content: | 
     Licens:: BSD 
     Link:: Here 
     Foo 
+1

我发现YAML禁止标签,因为它是一种空白的它是不可能的,我通过看实例知道。我确实将第二件事纠正为列表,因为这只是我忘了的一件事,但无论如何感谢您的帮助! – 2011-05-18 19:31:33

+0

我使用的是默认值?其中一个IronRuby 1.1.2应该与Ruby 1.9兼容 – 2011-05-18 19:32:10

+0

@Yet另一个极客:哦,是的,标签:继续奉献的礼物。我很高兴你把它理顺了。 – 2011-05-18 19:36:29