Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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


    // 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!

— asked November 21st 2010 by Mark Smillie
  • json

1 Answer

  • Accepted Answer


    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


    — answered November 21st 2010 by Chris Campbell
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.