如何修改多维对象以具有命名键
我如何修改此代码以返回下面的结构而不是代码当前生成的结构..
当前的 jQuery 代码和结构:
$(document).ready(function() {
var tweets = {};
$.getJSON('http://api.twitter.com/1/statuses/user_timeline.json?user_name=twitterapi&callback=?', function(data) {
$.each(data, function(i) {
var arr = {};
arr['text'] = this.text;
arr['id'] = this.id;
tweets[i] = [arr['text'] , arr['id']];
});
console.log(tweets);
返回
0 -> "tweet text(0), tweet id(0)"
0 -> "tweet text(0)"
1 -> "tweet id(0)"
1 -> "tweet text(1), tweet id(1)"
0 -> "tweet text(1)"
1 -> "tweet id(1)"
etc..
所需的..
tweets->
tweet ->
text -> "tweet text(0)"
id -> "tweet id(0)"
tweet ->
text -> "tweet text(1)"
id -> "tweet id(1)"
etc..
How do I modify this code to return the structure below instead of what the code currently generates..
current jQuery code and structure:
$(document).ready(function() {
var tweets = {};
$.getJSON('http://api.twitter.com/1/statuses/user_timeline.json?user_name=twitterapi&callback=?', function(data) {
$.each(data, function(i) {
var arr = {};
arr['text'] = this.text;
arr['id'] = this.id;
tweets[i] = [arr['text'] , arr['id']];
});
console.log(tweets);
returns
0 -> "tweet text(0), tweet id(0)"
0 -> "tweet text(0)"
1 -> "tweet id(0)"
1 -> "tweet text(1), tweet id(1)"
0 -> "tweet text(1)"
1 -> "tweet id(1)"
etc..
desired ..
tweets->
tweet ->
text -> "tweet text(0)"
id -> "tweet id(0)"
tweet ->
text -> "tweet text(1)"
id -> "tweet id(1)"
etc..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个
Try this