I have developed an application to write twitter search results as JSON objects to a results page as such:
for (Status tweet : tweets) {
Map<String, String> tweetResult = new LinkedHashMap<String, String>();
tweetResult.put("username", tweet.getUser().getScreenName());
tweetResult.put("status", tweet.getText());
tweetResult.put("date", tweet.getCreatedAt().toString());
tweetResult.put("retweets", String.valueOf(tweet.getRetweetCount()));
String resultJson = new Gson().toJson(tweetResult);
response.getWriter().write(resultJson);
}
This is called with AJAX/JQuery in the following:
$(document).ready(function() {
$.getJSON('SearchServlet', function(list) {
var table = $('#resultsTable');
$.each(list, function(index, tweet) {
$('<tr>').appendTo(table)
.append($('<td>').text(tweet.username))
.append($('<td>').text(tweet.status))
.append($('<td>').text(tweet.date))
.append($('<td>').text(tweet.retweets));
});
});
});
With the intention of populating a table with the results:
<body>
<div id="wrapper">
<div id="contentArea">
<div id="content">
<h2>Results:</h2>
<table id="resultsTable"></table>
</div>
</div>
</div>
</body>
The GET call is working perfectly and the results show up in the firebug console without a problem, however they're not appearing on the actual document itself as intended. I've tried a number of different approaches to this (including the answers here and here ).
Example of the JSON output:
{"username":"Dineen_","status":"RT @TwitterAds: Learn how to put Twitter to work for your small business! Download our small biz guide now: https://t.co/gdnMMYLI","date":"Tue Feb 26 08:37:11 GMT 2013","retweets":"22"}
Thanks in advance.