JSON Parse and Eval
I'm trying to parse through this but it won't parse. I can see the results Ti.API.info('mapped response to '+JSON.stringify(tweets)); BUT, when I go loop through, nothing happens. What am I missing here?
var loader = Titanium.Network.createHTTPClient();
// Sets the HTTP request method, and the URL to get data from
loader.open("GET","http://search.twitter.com/search.json?q=cnn");
// Runs the function when the data is ready for us to process
loader.onload = function()
{
//var tweets = eval('('+this.responseText+')');
var tweets = JSON.parse(this.responseText);
Ti.API.info('mapped response to '+JSON.stringify(tweets));
for(var i=0;i<tweets.length;i++)
{
var tweet = tweets[i].results.text; // The tweet message
var user = tweets[i].results.from_user; // The screen name of the user
var avatar = tweets[i].results.profile_image_url; // The profile image
// Create a row and set its height to auto
var row = Titanium.UI.createTableViewRow({height:'auto'});
Thank you!
1 Answer
-
Accepted Answer
Try
Ti.API.info("Number or tweets: " + tweets.length);
Maybe tweets.length is 0 since the json result has the "results" in it, you may have to do something like tweets['results'].length
Chris