使用Jade和express访问对象中的json对象

Accessing json objects within objects with Jade and express

本文关键字:对象 json 访问 Jade express 使用      更新时间:2023-09-26

我现在头发有点乱。我似乎不知道如何使用Jade访问下面json对象中的"媒体"内容。

   {
      "summary":"Jose Mourinho names his Real Madrid side to face Borussia Dortmund in the Champions League semi-final 24 hours early.",
      "type":"STY",
      "lastUpdated":"2013-04-23T16:31:39+00:00",
      "firstCreated":"2013-04-23T16:31:39+00:00",
      "hasShortForm":true,
      "media":{
         "images":{
            "index":{
               "67193384":{
                  "height":261,
                  "width":464,
                  "href":"http://thesun.co.uk/media/images/67193000/jpg/_67193384_67193383.jpg",
                  "altText":"Jose Mourinho"
               }
            }
         }
      },
   },

我可以访问摘要、类型、更新等。但我不知道如何访问media.images.index.67193384 中的图像元数据

for item in results
    p #{item.summary}
    p #{item.lastUpdated}
    p #{item.media[0]} // ???

有人能帮我弄清楚吗?我从未尝试过访问对象中的对象数据。此外,图像中的67193384对象。索引唯一的,并且总是因结果而异

谢谢!

有点黑客,但它有效:

- if (item.media && item.media.images)
  p #{item.media.images.index[Object.keys(item.media.images.index)[0]].height}
for item in results
    p= item.summary
    p= item.lastUpdated
    - for (var key in item.media.images) {break;}
    p= item.images.index[key].height

for循环用于获取密钥。