How do I modify this code to return the structure below instea开发者_Python百科d 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..
Try this
var tweets = [];
$.each(data, function(i) {
tweets.push({ "tweet": { "text": this.text , "id": this.id } });;
});
精彩评论