【发布时间】:2017-01-28 10:47:41
【问题描述】:
免责声明:我没有编程知识。
我只是尽力赶上。
在阅读(以及稍后尝试)this question 的答案时,我在想一个可能不错且有用的更新是在 json 术语中具有相同类型的信息,即如何检索“主页" 一个 Blogger 博客的 json 格式的 URL。
我试图自己弄清楚,因为我知道,例如,...
<script type="text/javascript">
function specialpost(json) {
document.write('<div>');
// VARIABLE DECLARATION
var i;
var j;
// LOOP
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 + "'";
var postTitle = json.feed.entry[i].title.$t;
var postContent = json.feed.entry[i].content.$t;
var item = '<h3><a href="' + postUrl + '" target="_blank">' + postTitle + '</a></h3><p>' + postContent + '</p>';
document.write(item);
}
document.write('</div>');
}
</script>
<script src="https://MYBLOG.blogspot.com/feeds/posts/default/-/special?max-results=NUMBER_OF_POSTS_DISPLAYED&alt=json-in-script&callback=specialpost"></script>
...会给我一个div,包含标题(包括链接)和所需数量的标有“特殊”的帖子的内容,但我在尝试中途有点困惑。
我正在使用jsonviewer 以可理解的树状形式查看我的博客的 json 代码,我猜测如果每个帖子的 URL 存储在 [] entry 内的某个位置,那么博客本身的 URL可能存储在[] link 内的某个地方。
问题:我说的对吗?
[] link 包含 4 个条目:{}0 {}1 {}2 和 {}3
每一个依次包含 3 个条目:
rel分别设置为"http://schemas.google.com/g/2005#feed""self""alternate"和"hub"type将前两个设置为"application/atom+xml",将第三个设置为text/html
- 未为{}3定义href设置为"http://MYBLOG.blogspot.com/feeds/posts/default"
(后跟?alt=json为我们提供了相同 json 代码的 URL
我进入了 jsonviewer 为了得到树状视图)"https://www.blogger.com/feed/1234567890123456789/posts/default?alt=json"
(我想,那个 19 位数字是一些机器生成的数字名称
Google 已分配给我的博客)"http://MYBLOG.blogspot.com"和"http://pubsubhubbub.appspot.com"。
我猜我要的是{}2
问题:我又说对了吗?如果是这样,我如何声明 var myblogUrl 的值设置为存储在该 {}2 条目中的 href?
最后但并非最不重要的一点:其他三个条目是做什么用的?存储在条目{}0 中的href 类似于将您带到一种订阅页面的订阅页面,您可以在其中选择要订阅相关博客的方式。真的是这样吗?
【问题讨论】:
标签: javascript json blogger