-1
基于以下模式,如何创建一个变量从json中获取标签?博主JSON - 如何获取类别/标签?
var postLink = function(entry) {
for (var j = 0; j < entry.link.length; j++) {
if (entry.link[j].rel == 'alternate') {
var postURL = entry.link[j].href;
return postURL;
break;
}
}
};
var postTitle = function(entry) {
var postTitle = entry.title.$t;
return postTitle;
};
function Full(json) {
for (var i = 0; i < json.feed.entry.length; i++) {
var entry = json.feed.entry[i];
var item1 = '<h3><a href="' + postLink(entry) + '">' + postTitle(entry) + '</a></h3>';
document.write(item1);
}
}
这段代码打印结果:
<script src="/feeds/posts/summary/-/LABEL?alt=json-in-script&callback=Full&max-results=2"></script>
结果是文章标题和链接只是......我只是想添加变量代码标签,以及...
我想里面的代码:
var postLabel = function(entry) {
//some code here
};
...和内部var item1
我会补充一点:+ postLabel(entry) +
我需要遵循postLink和postTitle的模式,但它超出了我的能力......感谢您的帮助!
你......忘了包括json以及你如何调用'Full'。这是jsonp吗? –
我确实要求澄清。你还没有提供任何。 –
我添加了一些更多的细节:) – willr