js/json:为什么我不能将 json.feed.entry[i].Content.$t 添加到这个变量定义中?

js/json: why can't I add json.feed.entry[i].Content.$t to this variable definition?

开始。同样的小项目。完全不同的查询。

这是更新后的代码:

<script type="text/javascript">
function recentpostslist(json) {
 document.write('<ul>');
 var i;
 var j;
 for (i = 0; i < json.feed.entry.length; i++)
 {
  for (j = 0; j < json.feed.entry[i].link.length; j++) {
   if (json.feed.entry[i].link[j].rel == 'alternate') {
    break;
   }
  }
var postUrl = "'" + json.feed.entry[i].link[j].href + "'";//bs
var postTitle = json.feed.entry[i].title.$t;
var item = "<h2>" + '<a href="' + postUrl + '" target="_blank">' + postTitle + "</a> </h2>";
 document.write(item);
 }
 document.write('</ul>');
 }
</script>
<script src="https://xxxxxxxxxx.blogspot.com/feeds/posts/summary/-/recommended?max-results=3&alt=json-in-script&callback=recentpostslist"></script>

它的作用是列出已标记为 "recommended" 的博客的 3 个最新帖子的标题。

我想我可以声明另一个变量,就在 var item 定义之上,如...

var postContent = json.feed.entry[i].content.$t;

...并将其添加到 'var item' 值,如...

var item = "<h2>" + '<a href="' + postUrl + '" target="_blank">' + postTitle + "</a> </h2> <p>" + postContent + "</p>";

...或类似的东西;我的意图是将帖子的内容(不仅仅是标题)包含在显示的内容中。

但这似乎不起作用。我错过了什么吗?

您使用的 URL 包含单词 summary;如果您改用 default,显然 json 数据也将包含内容。