maplefu0602 / spyc

Automatically exported from code.google.com/p/spyc
MIT License
0 stars 0 forks source link

How to get data inside curly brackets? #56

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I have a YAML file that has something like this:

images:
- {image: image1.jpg, type: picture}
- {image: image2.jpg, type: picture}

I've tried to search for a solution and found none. I've read gone through the 
examples but they just show how to dump a PHP array into YML that looks like 
that and not the other way around.

Is this even supported?

I desperately need help with this!

Original issue reported on code.google.com by yennan.m...@gmail.com on 26 Oct 2012 at 12:10

GoogleCodeExporter commented 8 years ago
I don't know what problem you are trying to solve.

What I think is:

1.- If you're tring to get a key called "images", which holds a list of two 
associative arrays defined in one line each one, you should write in YAML:

images:
 - {image: image1.jpg, type: picture}
 - {image: image2.jpg, type: picture}

i.e. you should indent the list items, so that they belong to the key above 
them.

With that YAML, after parsing with spyc, you get this:

array(1) {
  ["images"]=>
  array(2) {
    [0]=>
    array(2) {
      ["image"]=>
      string(10) "image1.jpg"
      ["type"]=>
      string(7) "picture"
    }
    [1]=>
    array(2) {
      ["image"]=>
      string(10) "image2.jpg"
      ["type"]=>
      string(7) "picture"
    }
  }
}

2.- With what you have just published, you get a list with three items, one 
with key "images", and two other with correlative keys "0" and "1".

array(3) {
  ["images"]=>
  string(0) ""
  [0]=>
  array(2) {
    ["image"]=>
    string(10) "image1.jpg"
    ["type"]=>
    string(7) "picture"
  }
  [1]=>
  array(2) {
    ["image"]=>
    string(10) "image2.jpg"
    ["type"]=>
    string(7) "picture"
  }
}

Original comment by nozim...@gmail.com on 16 Jan 2013 at 9:34

GoogleCodeExporter commented 8 years ago

Original comment by vlad.and...@gmail.com on 9 Sep 2013 at 4:02