将数据提要存储为变量 [英] Storing data feed as variables

查看:71
本文介绍了将数据提要存储为变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Java,JQuery和JSON的新手,我想知道是否可以将RSS提要中的数据提要存储为变量.

I am new to Javascript,JQuery, and JSON and i was wondering if it was possible to store a feed of data from say an RSS feed as a variable.

例如,我有这段代码,它接收来自youtube的供稿,并通过它进行解析以获取视频ID.每次通过之后,我希望它将要存储的数据存储在不同的变量中.

For example i have this code which recieves a feed from youtube and parses through it to get the video Ids. after each pass i would like it to store the data to be stored in a different variable.

代码如下.

$(document).ready(function () {
 getYouTubeAllInfo();
 });    

function getYouTubeAllInfo() {
       $.getJSON('http://gdata.youtube.com/feeds/users/SkyDoesMinecraft/uploads?orderby=updated&alt=json-in-script&callback=?&start-index=1&max-results=15', 
   function(data){
       $.each(data.feed.entry, function(i, item){
           var id = item['id']['$t'];
           id = id.replace("http://gdata.youtube.com/feeds/videos/","");
       });
   }); 
   }

您可以在此处查看实时版本: Jsfiddle div后面会显示一个附加内容它会做什么.

you can view a live version here: Jsfiddle there is an append to a div to show you what it does.

但是我需要做的是将一个迭代保存到一个变量中,将另一个保存到另一个变量中.有什么建议吗?

but what i need it to do is save one iteration to one variable and the next to another. any suggestions?

推荐答案

您可以将其存储为数组:

You can store it as an array:

var feedIds = [];
function getYouTubeAllInfo() {
   $.getJSON('http://gdata.youtube.com/feeds/users/SkyDoesMinecraft/uploads?orderby=updated&alt=json-in-script&callback=?&start-index=1&max-results=15', 
       function(data){
           $.each(data.feed.entry, function(i, item){
               var id = item['id']['$t'];
               id = id.replace("http://gdata.youtube.com/feeds/videos/","");
               feedIds.push(item['id']);
           });
           console.log(feedIds);
   }); 
}

这篇关于将数据提要存储为变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆