$(function(){
$.ajax({
url:'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=user_name&callback=?',
//dataType:'json',
success:function(data){$('body').append('the data is' +data);}
});
});
the above code with dataType line prints out [objects] while with the dataType line commented it prints out nothing ...how can i get it to print the json output from the server rather then the javascript object?
Try
success:function(data){$('body').append('the data is' +data.urKeyname);}
hope you are using firebug,
add this to your code:
success:function(data){console.log(data);}
check the firebug console to see what data object has. Acccordingly use the object like
success:function(data){$('body').append('the data is' +data.key);}
Or use this short hand for getting json encoded data
$.getJSON('ajax/test.json', function(data) {
$('.result').html('<p>' + data.foo + '</p>'
+ '<p>' + data.baz[1] + '</p>');
});
more info at getJSONdocumentation
First, you may want to check out Twitter's API docs, it has all this broken down with descriptions, here's the direct link to user_timeline
.
Alternatively, here's the manual route :) To inspect it you have a few options, if you're using Firefox/Firebug or Chrome, you can log it to the console, like this:
$.ajax({
url:'http://api.twitter.com/1/statuses/user_timeline.json?screen_name=user_name&callback=?',
dataType:'json',
success:function(data){ console.log(data); }
});
Another option is just visiting the URL: http://api.twitter.com/1/statuses/user_timeline.json?screen_name=user_name&callback= Then take the result and pop it in something like JSONLint to format it for easier browsing.
What you'll probably end up wanting is something like this:
data[0].user.friends_count